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
Properties
events
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 }
Methods
add()
add()
Preview
add(command)
Description
Add command to the dispatcher handler
Defined in dispatcher/dispatcher.ts:401
Parameters
Name | Details |
---|---|
command
|
|
Return
string
addQueueElement()
addQueueElement()
Preview
addQueueElement<Command>(queueKey, dispatcherDump)
Description
Add new element to storage
Defined in dispatcher/dispatcher.ts:137
Parameters
Return
void
addRunningRequest()
addRunningRequest()
Preview
addRunningRequest(queueKey, requestId, command)
Description
Add request to the running requests list
Defined in dispatcher/dispatcher.ts:298
Parameters
Return
void
cancelRunningRequest()
cancelRunningRequest()
Preview
cancelRunningRequest(queueKey, requestId)
Description
Cancel started request, but do NOT remove it from main storage
Defined in dispatcher/dispatcher.ts:331
Parameters
Return
void
cancelRunningRequests()
cancelRunningRequests()
Preview
cancelRunningRequests(queueKey)
Description
Cancel all started requests, but do NOT remove it from main storage
Defined in dispatcher/dispatcher.ts:322
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
void
clear()
clear()
Preview
clear()
Description
Clear all running requests and storage
Defined in dispatcher/dispatcher.ts:223
Return
void
clearQueue()
clearQueue()
Preview
clearQueue(queueKey)
Description
Clear requests from queue cache
Defined in dispatcher/dispatcher.ts:162
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
{
requests: any[];
stopped: boolean;
}
createStorageElement()
createStorageElement()
Preview
createStorageElement<Command>(command)
Description
Create storage element from command
Defined in dispatcher/dispatcher.ts:380
Parameters
Name | Details |
---|---|
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()
delete()
Preview
delete(queueKey, requestId, abortKey)
Description
Delete from the storage and cancel request
Defined in dispatcher/dispatcher.ts:445
Parameters
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()
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
Return
void
deleteRunningRequests()
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
Name | Details |
---|---|
queueKey
|
|
Return
void
flush()
flush()
Preview
flush()
Description
Flush all available requests from all queues
Defined in dispatcher/dispatcher.ts:207
Return
Promise<void>
flushQueue()
flushQueue()
Preview
flushQueue(queueKey)
Description
Method used to flush the queue requests
Defined in dispatcher/dispatcher.ts:177
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
Promise<void>
getAllRunningRequest()
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()
getIsActiveQueue()
Preview
getIsActiveQueue(queueKey)
Description
Get value of the active queue status based on the stopped status
Defined in dispatcher/dispatcher.ts:127
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
boolean
getQueue()
getQueue()
Preview
getQueue<Command>(queueKey)
Description
Return queue state object
Defined in dispatcher/dispatcher.ts:107
Parameters
Name | Details |
---|---|
queueKey
|
|
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()
getQueueRequestCount()
Preview
getQueueRequestCount(queueKey)
Description
Get count of requests from the same queueKey
Defined in dispatcher/dispatcher.ts:364
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
number
getQueuesKeys()
getQueuesKeys()
Preview
getQueuesKeys()
Description
Return all
Defined in dispatcher/dispatcher.ts:100
Return
string[]
getRequest()
getRequest()
Preview
getRequest<Command>(queueKey, requestId)
Description
Return request from queue state
Defined in dispatcher/dispatcher.ts:117
Parameters
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()
getRunningRequest()
Preview
getRunningRequest(queueKey, requestId)
Description
Get running request by id
Defined in dispatcher/dispatcher.ts:290
Parameters
Return
{
command: Command<any, any, any, any, any, any, any, any, any, any, any>;
requestId: string;
}
getRunningRequests()
getRunningRequests()
Preview
getRunningRequests(queueKey)
Description
Get currently running requests
Defined in dispatcher/dispatcher.ts:283
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
{
command: Command<any, any, any, any, any, any, any, any, any, any, any>;
requestId: string;
}[]
hasRunningRequest()
hasRunningRequest()
Preview
hasRunningRequest(queueKey, requestId)
Description
Check if request is currently processing
Defined in dispatcher/dispatcher.ts:314
Parameters
Return
boolean
hasRunningRequests()
hasRunningRequests()
Preview
hasRunningRequests(queueKey)
Description
Get the value based on the currently running requests
Defined in dispatcher/dispatcher.ts:307
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
boolean
incrementQueueRequestCount()
incrementQueueRequestCount()
Preview
incrementQueueRequestCount(queueKey)
Description
Add request count to the queueKey
Defined in dispatcher/dispatcher.ts:371
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
void
pause()
pause()
Preview
pause(queueKey)
Description
Pause request queue, but not cancel already started requests
Defined in dispatcher/dispatcher.ts:73
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
void
performRequest()
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
Name | Details |
---|---|
storageElement
|
|
Return
Promise<void | DispatcherData<CommandInstance>>
setQueue()
setQueue()
Preview
setQueue<Command>(queueKey, queue)
Description
Set new queue storage value
Defined in dispatcher/dispatcher.ts:149
Parameters
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()
start()
Preview
start(queueKey)
Description
Start request handling by queueKey
Defined in dispatcher/dispatcher.ts:59
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
void
startRequest()
startRequest()
Preview
startRequest(queueKey, requestId)
Description
Start particular request
Defined in dispatcher/dispatcher.ts:241
Parameters
Return
void