Skip to main content

Dispatcher

Class


Preview

new Dispatcher(builder, options)

Description

Dispatcher class was made to store controlled request Fetches, and firing them all-at-once or one-by-one in command queue.

Generally requests should be flushed at the same time, the queue provide mechanism to fire them in the order.

Import

import { Dispatcher } from "@better-typed/hyper-fetch"

Parameters

Name Type Default Value Description
builder BuilderInstance - -
options DispatcherOptionsType - -

Methods

stopRequest()

Stop particular request

stopRequest(queueKey, requestId)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -

stop()

Stop request queue and cancel all started requests - those will be treated like not started

stop(queueKey)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -

startRequest()

Start particular request

startRequest(queueKey, requestId)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -

start()

Start request handling by queueKey

start(queueKey)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -

setQueue()

Set new queue storage value

setQueue<Command>(queueKey, queue)

Parameters

Name Type Default Value Description
queueKey string - -
queue DispatcherData<Command> - -

performRequest()

Request can run for some time, once it's done, we have to check if it's successful or if it was aborted

It can be different once the previous call was set as cancelled and removed from queue before this request got resolved

performRequest(storageElement)
Returns a Promise<void | DispatcherData<CommandInstance>>

Parameters

Name Type Default Value Description
storageElement DispatcherDumpValueType<CommandInstance> - -

pause()

Pause request queue, but not cancel already started requests

pause(queueKey)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -

incrementQueueRequestCount()

Add request count to the queueKey

incrementQueueRequestCount(queueKey)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -

hasRunningRequests()

Get the value based on the currently running requests

hasRunningRequests(queueKey)
Returns a boolean

Parameters

Name Type Default Value Description
queueKey string - -

hasRunningRequest()

Check if request is currently processing

hasRunningRequest(queueKey, requestId)
Returns a boolean

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -

getRunningRequests()

Get currently running requests

getRunningRequests(queueKey)

Parameters

Name Type Default Value Description
queueKey string - -

getRunningRequest()

Get running request by id

getRunningRequest(queueKey, requestId)

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -

getRequest()

Return request from queue state

getRequest<Command>(queueKey, requestId)

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -

getQueuesKeys()

Return all

getQueuesKeys()
Returns a string[]

getQueueRequestCount()

Get count of requests from the same queueKey

getQueueRequestCount(queueKey)
Returns a number

Parameters

Name Type Default Value Description
queueKey string - -

getQueue()

Return queue state object

getQueue<Command>(queueKey)

Parameters

Name Type Default Value Description
queueKey string - -

getIsActiveQueue()

Get value of the active queue status based on the stopped status

getIsActiveQueue(queueKey)
Returns a boolean

Parameters

Name Type Default Value Description
queueKey string - -

getAllRunningRequest()

Get currently running requests from all queueKeys

getAllRunningRequest()

flushQueue()

Method used to flush the queue requests

flushQueue(queueKey)
Returns a Promise<void>

Parameters

Name Type Default Value Description
queueKey string - -

flush()

Flush all available requests from all queues

flush()
Returns a Promise<void>

deleteRunningRequests()

Delete all started requests, but do NOT clear it from queue and do NOT cancel them

deleteRunningRequests(queueKey)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -

deleteRunningRequest()

Delete request by id, but do NOT clear it from queue and do NOT cancel them

deleteRunningRequest(queueKey, requestId)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -

delete()

Delete from the storage and cancel request

delete(queueKey, requestId, abortKey)

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -
abortKey string - -

createStorageElement()

Create storage element from command

createStorageElement<Command>(command)

Parameters

Name Type Default Value Description
command Command - -

clearQueue()

Clear requests from queue cache

clearQueue(queueKey)
Returns a { requests: any[], stopped: boolean }

Parameters

Name Type Default Value Description
queueKey string - -

clear()

Clear all running requests and storage

clear()
Returns a void

cancelRunningRequests()

Cancel all started requests, but do NOT remove it from main storage

cancelRunningRequests(queueKey)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -

cancelRunningRequest()

Cancel started request, but do NOT remove it from main storage

cancelRunningRequest(queueKey, requestId)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -

addRunningRequest()

Add request to the running requests list

addRunningRequest(queueKey, requestId, command)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -
requestId string - -
command CommandInstance - -

addQueueElement()

Add new element to storage

addQueueElement<Command>(queueKey, dispatcherDump)
Returns a void

Parameters

Name Type Default Value Description
queueKey string - -
dispatcherDump DispatcherDumpValueType<Command> - -

add()

Add command to the dispatcher handler

add(command)
Returns a string

Parameters

Name Type Default Value Description
command CommandInstance - -

References