Skip to main content
Version: 1.x.x

Dispatcher


import { Dispatcher } from "@hyper-fetch/core"

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.

Defined in dispatcher/dispatcher.ts:25

Parameters

NameDetails

builder

Required

BuilderInstance

options

Optional

DispatcherOptionsType

Properties

builder

Description

Defined in dispatcher/dispatcher.ts:35

Type

BuilderInstance

emitter

Description

Defined in dispatcher/dispatcher.ts:26

Type

EventEmitter

events

Description

Defined in dispatcher/dispatcher.ts:27

Type

{ onDrained: <Command>(queueKey: string, callback: (values: DispatcherData<Command>) => void) => VoidFunction; onQueueChange: <Command>(queueKey: string, callback: (values: DispatcherData<Command>) => void) => VoidFunction; onQueueStatus: <Command>(queueKey: string, callback: (values: DispatcherData<Command>) => void) => VoidFunction; setDrained: <Command>(queueKey: string, values: DispatcherData<Command>) => void; setQueueChanged: <Command>(queueKey: string, values: DispatcherData<Command>) => void; setQueueStatus: <Command>(queueKey: string, values: DispatcherData<Command>) => void }

options

Description

Defined in dispatcher/dispatcher.ts:35

Type

DispatcherOptionsType

storage

Description

Defined in dispatcher/dispatcher.ts:28

Type

DispatcherStorageType

Methods

add()

Preview

add(command)

Description

Add command to the dispatcher handler

Defined in dispatcher/dispatcher.ts:401

Parameters

NameDetails

command

Required

CommandInstance

Return

string

addQueueElement()

Preview

addQueueElement<Command>(queueKey, dispatcherDump)

Description

Add new element to storage

Defined in dispatcher/dispatcher.ts:137

Parameters

NameDetails

queueKey

Required

string

dispatcherDump

Required

DispatcherDumpValueType<Command>

Return

void

addRunningRequest()

Preview

addRunningRequest(queueKey, requestId, command)

Description

Add request to the running requests list

Defined in dispatcher/dispatcher.ts:298

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

command

Required

CommandInstance

Return

void

cancelRunningRequest()

Preview

cancelRunningRequest(queueKey, requestId)

Description

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

Defined in dispatcher/dispatcher.ts:331

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

void

cancelRunningRequests()

Preview

cancelRunningRequests(queueKey)

Description

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

Defined in dispatcher/dispatcher.ts:322

Parameters

NameDetails

queueKey

Required

string

Return

void

clear()

Preview

clear()

Description

Clear all running requests and storage

Defined in dispatcher/dispatcher.ts:223

Return

void

clearQueue()

Preview

clearQueue(queueKey)

Description

Clear requests from queue cache

Defined in dispatcher/dispatcher.ts:162

Parameters

NameDetails

queueKey

Required

string

Return

{
requests: any[];
stopped: boolean;
}

createStorageElement()

Preview

createStorageElement<Command>(command)

Description

Create storage element from command

Defined in dispatcher/dispatcher.ts:380

Parameters

NameDetails

command

Required

Command

Return

{
commandDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
commandOptions: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean;
disableResponseInterceptors: boolean;
effectKey: string;
endpoint: GenericEndpoint;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
data: MappedData extends undefined ? RequestDataType : MappedData | \null\ | \undefined\;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean | undefined;
disableResponseInterceptors: boolean | undefined;
effectKey: string;
endpoint: string;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions | T extends Command<any, any, any, any, any, any, infer O, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParamsType | \null\ | \undefined\;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
updatedAbortKey: boolean;
updatedCacheKey: boolean;
updatedEffectKey: boolean;
updatedQueueKey: boolean;
used: boolean;
};
requestId: string;
retries: number;
stopped: boolean;
timestamp: number;
}

delete()

Preview

delete(queueKey, requestId, abortKey)

Description

Delete from the storage and cancel request

Defined in dispatcher/dispatcher.ts:445

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

abortKey

Required

string

Return

{
requests: {
commandDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
commandOptions: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean;
disableResponseInterceptors: boolean;
effectKey: string;
endpoint: GenericEndpoint;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
data: MappedData extends undefined ? RequestDataType : MappedData | \null\ | \undefined\;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean | undefined;
disableResponseInterceptors: boolean | undefined;
effectKey: string;
endpoint: string;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions | T extends Command<any, any, any, any, any, any, infer O, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParamsType | \null\ | \undefined\;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
updatedAbortKey: boolean;
updatedCacheKey: boolean;
updatedEffectKey: boolean;
updatedQueueKey: boolean;
used: boolean;
};
requestId: string;
retries: number;
stopped: boolean;
timestamp: number;
}[];
stopped: boolean;
}

deleteRunningRequest()

Preview

deleteRunningRequest(queueKey, requestId)

Description

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

Defined in dispatcher/dispatcher.ts:353

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

void

deleteRunningRequests()

Preview

deleteRunningRequests(queueKey)

Description

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

Defined in dispatcher/dispatcher.ts:346

Parameters

NameDetails

queueKey

Required

string

Return

void

flush()

Preview

flush()

Description

Flush all available requests from all queues

Defined in dispatcher/dispatcher.ts:207

Return

Promise<void>

flushQueue()

Preview

flushQueue(queueKey)

Description

Method used to flush the queue requests

Defined in dispatcher/dispatcher.ts:177

Parameters

NameDetails

queueKey

Required

string

Return

Promise<void>

getAllRunningRequest()

Preview

getAllRunningRequest()

Description

Get currently running requests from all queueKeys

Defined in dispatcher/dispatcher.ts:276

Return

{
command: Command<any, any, any, any, any, any, any, any, any, any, any>;
requestId: string;
}[]

getIsActiveQueue()

Preview

getIsActiveQueue(queueKey)

Description

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

Defined in dispatcher/dispatcher.ts:127

Parameters

NameDetails

queueKey

Required

string

Return

boolean

getQueue()

Preview

getQueue<Command>(queueKey)

Description

Return queue state object

Defined in dispatcher/dispatcher.ts:107

Parameters

NameDetails

queueKey

Required

string

Return

{
requests: {
commandDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
commandOptions: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean;
disableResponseInterceptors: boolean;
effectKey: string;
endpoint: GenericEndpoint;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
data: MappedData extends undefined ? RequestDataType : MappedData | \null\ | \undefined\;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean | undefined;
disableResponseInterceptors: boolean | undefined;
effectKey: string;
endpoint: string;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions | T extends Command<any, any, any, any, any, any, infer O, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParamsType | \null\ | \undefined\;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
updatedAbortKey: boolean;
updatedCacheKey: boolean;
updatedEffectKey: boolean;
updatedQueueKey: boolean;
used: boolean;
};
requestId: string;
retries: number;
stopped: boolean;
timestamp: number;
}[];
stopped: boolean;
}

getQueueRequestCount()

Preview

getQueueRequestCount(queueKey)

Description

Get count of requests from the same queueKey

Defined in dispatcher/dispatcher.ts:364

Parameters

NameDetails

queueKey

Required

string

Return

number

getQueuesKeys()

Preview

getQueuesKeys()

Description

Return all

Defined in dispatcher/dispatcher.ts:100

Return

string[]

getRequest()

Preview

getRequest<Command>(queueKey, requestId)

Description

Return request from queue state

Defined in dispatcher/dispatcher.ts:117

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

{
commandDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
commandOptions: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean;
disableResponseInterceptors: boolean;
effectKey: string;
endpoint: GenericEndpoint;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
data: MappedData extends undefined ? RequestDataType : MappedData | \null\ | \undefined\;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean | undefined;
disableResponseInterceptors: boolean | undefined;
effectKey: string;
endpoint: string;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions | T extends Command<any, any, any, any, any, any, infer O, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParamsType | \null\ | \undefined\;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
updatedAbortKey: boolean;
updatedCacheKey: boolean;
updatedEffectKey: boolean;
updatedQueueKey: boolean;
used: boolean;
};
requestId: string;
retries: number;
stopped: boolean;
timestamp: number;
}

getRunningRequest()

Preview

getRunningRequest(queueKey, requestId)

Description

Get running request by id

Defined in dispatcher/dispatcher.ts:290

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

{
command: Command<any, any, any, any, any, any, any, any, any, any, any>;
requestId: string;
}

getRunningRequests()

Preview

getRunningRequests(queueKey)

Description

Get currently running requests

Defined in dispatcher/dispatcher.ts:283

Parameters

NameDetails

queueKey

Required

string

Return

{
command: Command<any, any, any, any, any, any, any, any, any, any, any>;
requestId: string;
}[]

hasRunningRequest()

Preview

hasRunningRequest(queueKey, requestId)

Description

Check if request is currently processing

Defined in dispatcher/dispatcher.ts:314

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

boolean

hasRunningRequests()

Preview

hasRunningRequests(queueKey)

Description

Get the value based on the currently running requests

Defined in dispatcher/dispatcher.ts:307

Parameters

NameDetails

queueKey

Required

string

Return

boolean

incrementQueueRequestCount()

Preview

incrementQueueRequestCount(queueKey)

Description

Add request count to the queueKey

Defined in dispatcher/dispatcher.ts:371

Parameters

NameDetails

queueKey

Required

string

Return

void

pause()

Preview

pause(queueKey)

Description

Pause request queue, but not cancel already started requests

Defined in dispatcher/dispatcher.ts:73

Parameters

NameDetails

queueKey

Required

string

Return

void

performRequest()

Preview

performRequest(storageElement)

Description

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

Defined in dispatcher/dispatcher.ts:478

Parameters

NameDetails

storageElement

Required

DispatcherDumpValueType<CommandInstance>

Return

Promise<void | DispatcherData<CommandInstance>>

setQueue()

Preview

setQueue<Command>(queueKey, queue)

Description

Set new queue storage value

Defined in dispatcher/dispatcher.ts:149

Parameters

NameDetails

queueKey

Required

string

queue

Required

DispatcherData<Command>

Return

{
requests: {
commandDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
commandOptions: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean;
disableResponseInterceptors: boolean;
effectKey: string;
endpoint: GenericEndpoint;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
data: MappedData extends undefined ? RequestDataType : MappedData | \null\ | \undefined\;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean | undefined;
disableResponseInterceptors: boolean | undefined;
effectKey: string;
endpoint: string;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions | T extends Command<any, any, any, any, any, any, infer O, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParamsType | \null\ | \undefined\;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
updatedAbortKey: boolean;
updatedCacheKey: boolean;
updatedEffectKey: boolean;
updatedQueueKey: boolean;
used: boolean;
};
requestId: string;
retries: number;
stopped: boolean;
timestamp: number;
}[];
stopped: boolean;
}

start()

Preview

start(queueKey)

Description

Start request handling by queueKey

Defined in dispatcher/dispatcher.ts:59

Parameters

NameDetails

queueKey

Required

string

Return

void

startRequest()

Preview

startRequest(queueKey, requestId)

Description

Start particular request

Defined in dispatcher/dispatcher.ts:241

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

void

stop()

Preview

stop(queueKey)

Description

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

Defined in dispatcher/dispatcher.ts:85

Parameters

NameDetails

queueKey

Required

string

Return

void

stopRequest()

Preview

stopRequest(queueKey, requestId)

Description

Stop particular request

Defined in dispatcher/dispatcher.ts:258

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

void