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:24
Parameters
Properties
events
events
Description
Defined in dispatcher/dispatcher.ts:26
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 }
Methods
add()
add()
Preview
add(request)
Description
Add request to the dispatcher handler
Defined in dispatcher/dispatcher.ts:400
Parameters
Name | Details |
---|---|
request
|
|
Return
string
addQueueElement()
addQueueElement()
Preview
addQueueElement<Request>(queueKey, dispatcherDump)
Description
Add new element to storage
Defined in dispatcher/dispatcher.ts:136
Parameters
Return
void
addRunningRequest()
addRunningRequest()
Preview
addRunningRequest(queueKey, requestId, request)
Description
Add request to the running requests list
Defined in dispatcher/dispatcher.ts:297
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:330
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:321
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
void
clear()
clear()
Preview
clear()
Description
Clear all running requests and storage
Defined in dispatcher/dispatcher.ts:222
Return
void
clearQueue()
clearQueue()
Preview
clearQueue(queueKey)
Description
Clear requests from queue cache
Defined in dispatcher/dispatcher.ts:161
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
{
requests: any[];
stopped: boolean;
}
createStorageElement()
createStorageElement()
Preview
createStorageElement<Request>(request)
Description
Create storage element from request
Defined in dispatcher/dispatcher.ts:379
Parameters
Name | Details |
---|---|
request
|
|
Return
{
request: Request;
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:444
Parameters
Return
{
requests: {
request: Request;
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:352
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:345
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
void
flush()
flush()
Preview
flush()
Description
Flush all available requests from all queues
Defined in dispatcher/dispatcher.ts:206
Return
Promise<void>
flushQueue()
flushQueue()
Preview
flushQueue(queueKey)
Description
Method used to flush the queue requests
Defined in dispatcher/dispatcher.ts:176
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
Promise<void>
getAllRunningRequest()
getAllRunningRequest()
Preview
getAllRunningRequest()
Description
Get currently running requests from all queueKeys
Defined in dispatcher/dispatcher.ts:275
Return
{
request: Request<any, any, any, any, any, any, AdapterType<any, any, any, any, any>, any, any, any>;
requestId: string;
timestamp: number;
}[]
getIsActiveQueue()
getIsActiveQueue()
Preview
getIsActiveQueue(queueKey)
Description
Get value of the active queue status based on the stopped status
Defined in dispatcher/dispatcher.ts:126
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
boolean
getQueue()
getQueue()
Preview
getQueue<Request>(queueKey)
Description
Return queue state object
Defined in dispatcher/dispatcher.ts:106
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
{
requests: {
request: Request;
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:363
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
number
getQueuesKeys()
getQueuesKeys()
Preview
getQueuesKeys()
Description
Return all
Defined in dispatcher/dispatcher.ts:99
Return
string[]
getRequest()
getRequest()
Preview
getRequest<Request>(queueKey, requestId)
Description
Return request from queue state
Defined in dispatcher/dispatcher.ts:116
Parameters
Return
{
request: Request;
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:289
Parameters
Return
{
request: Request<any, any, any, any, any, any, AdapterType<any, any, any, any, any>, any, any, any>;
requestId: string;
timestamp: number;
}
getRunningRequests()
getRunningRequests()
Preview
getRunningRequests(queueKey)
Description
Get currently running requests
Defined in dispatcher/dispatcher.ts:282
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
{
request: Request<any, any, any, any, any, any, AdapterType<any, any, any, any, any>, any, any, any>;
requestId: string;
timestamp: number;
}[]
hasRunningRequest()
hasRunningRequest()
Preview
hasRunningRequest(queueKey, requestId)
Description
Check if request is currently processing
Defined in dispatcher/dispatcher.ts:313
Parameters
Return
boolean
hasRunningRequests()
hasRunningRequests()
Preview
hasRunningRequests(queueKey)
Description
Get the value based on the currently running requests
Defined in dispatcher/dispatcher.ts:306
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
boolean
incrementQueueRequestCount()
incrementQueueRequestCount()
Preview
incrementQueueRequestCount(queueKey)
Description
Add request count to the queueKey
Defined in dispatcher/dispatcher.ts:370
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:72
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:476
Parameters
Name | Details |
---|---|
storageElement
|
|
Return
Promise<void | QueueDataType<RequestInstance>>
setQueue()
setQueue()
Preview
setQueue<Request>(queueKey, queue)
Description
Set new queue storage value
Defined in dispatcher/dispatcher.ts:148
Parameters
Return
{
requests: {
request: Request;
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:58
Parameters
Name | Details |
---|---|
queueKey
|
|
Return
void
startRequest()
startRequest()
Preview
startRequest(queueKey, requestId)
Description
Start particular request
Defined in dispatcher/dispatcher.ts:240
Parameters
Return
void