Skip to main content
Version: Current

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 request 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

client

Required

ClientInstance

options

Optional

DispatcherOptionsType

Properties

client

Description

Defined in dispatcher/dispatcher.ts:35

Type

ClientInstance

emitter

Description

Defined in dispatcher/dispatcher.ts:26

Type

EventEmitter

events

Description

Defined in dispatcher/dispatcher.ts:27

Type

{ onDrained: <Request>(queueKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction; onQueueChange: <Request>(queueKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction; onQueueStatus: <Request>(queueKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction; setDrained: <Request>(queueKey: string, values: QueueDataType<Request>) => void; setQueueChanged: <Request>(queueKey: string, values: QueueDataType<Request>) => void; setQueueStatus: <Request>(queueKey: string, values: QueueDataType<Request>) => 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(request)

Description

Add request to the dispatcher handler

Defined in dispatcher/dispatcher.ts:401

Parameters

NameDetails

request

Required

RequestInstance

Return

string

addQueueElement()

Preview

addQueueElement<Request>(queueKey, dispatcherDump)

Description

Add new element to storage

Defined in dispatcher/dispatcher.ts:137

Parameters

NameDetails

queueKey

Required

string

dispatcherDump

Required

DispatcherStorageValueType<Request>

Return

void

addRunningRequest()

Preview

addRunningRequest(queueKey, requestId, request)

Description

Add request to the running requests list

Defined in dispatcher/dispatcher.ts:298

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

request

Required

RequestInstance

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<Request>(request)

Description

Create storage element from request

Defined in dispatcher/dispatcher.ts:380

Parameters

NameDetails

request

Required

Request

Return

{
requestDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
data: MappedData extends never ? Payload : 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: AdapterOptions | T extends Request<any, any, any, any, any, any, infer O, any, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParams | \null\ | \undefined\;
queueKey: string;
queued: boolean;
requestOptions: {
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: AdapterOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
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: {
requestDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
data: MappedData extends never ? Payload : 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: AdapterOptions | T extends Request<any, any, any, any, any, any, infer O, any, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParams | \null\ | \undefined\;
queueKey: string;
queued: boolean;
requestOptions: {
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: AdapterOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
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

{
request: Request<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<Request>(queueKey)

Description

Return queue state object

Defined in dispatcher/dispatcher.ts:107

Parameters

NameDetails

queueKey

Required

string

Return

{
requests: {
requestDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
data: MappedData extends never ? Payload : 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: AdapterOptions | T extends Request<any, any, any, any, any, any, infer O, any, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParams | \null\ | \undefined\;
queueKey: string;
queued: boolean;
requestOptions: {
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: AdapterOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
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<Request>(queueKey, requestId)

Description

Return request from queue state

Defined in dispatcher/dispatcher.ts:117

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

{
requestDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
data: MappedData extends never ? Payload : 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: AdapterOptions | T extends Request<any, any, any, any, any, any, infer O, any, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParams | \null\ | \undefined\;
queueKey: string;
queued: boolean;
requestOptions: {
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: AdapterOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
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

{
request: Request<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

{
request: Request<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

DispatcherStorageValueType<RequestInstance>

Return

Promise<void | QueueDataType<RequestInstance>>

setQueue()

Preview

setQueue<Request>(queueKey, queue)

Description

Set new queue storage value

Defined in dispatcher/dispatcher.ts:149

Parameters

NameDetails

queueKey

Required

string

queue

Required

QueueDataType<Request>

Return

{
requests: {
requestDump: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
data: MappedData extends never ? Payload : 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: AdapterOptions | T extends Request<any, any, any, any, any, any, infer O, any, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParams | \null\ | \undefined\;
queueKey: string;
queued: boolean;
requestOptions: {
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: AdapterOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
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