Skip to main content
Version: 5.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 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

NameDetails

client

Required

ClientInstance

options

Optional

DispatcherOptionsType

Properties

client

Description

Defined in dispatcher/dispatcher.ts:34

Type

ClientInstance

emitter

Description

Defined in dispatcher/dispatcher.ts:25

Type

EventEmitter

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 }

options

Description

Defined in dispatcher/dispatcher.ts:34

Type

DispatcherOptionsType

storage

Description

Defined in dispatcher/dispatcher.ts:27

Type

DispatcherStorageType

Methods

add()

Preview

add(request)

Description

Add request to the dispatcher handler

Defined in dispatcher/dispatcher.ts:400

Parameters

NameDetails

request

Required

RequestInstance

Return

string

addQueueElement()

Preview

addQueueElement<Request>(queueKey, dispatcherDump)

Description

Add new element to storage

Defined in dispatcher/dispatcher.ts:136

Parameters

NameDetails

queueKey

Required

string

dispatcherDump

Required

QueueElementType<Request>

Return

void

addRunningRequest()

Preview

addRunningRequest(queueKey, requestId, request)

Description

Add request to the running requests list

Defined in dispatcher/dispatcher.ts:297

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:330

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:321

Parameters

NameDetails

queueKey

Required

string

Return

void

clear()

Preview

clear()

Description

Clear all running requests and storage

Defined in dispatcher/dispatcher.ts:222

Return

void

clearQueue()

Preview

clearQueue(queueKey)

Description

Clear requests from queue cache

Defined in dispatcher/dispatcher.ts:161

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:379

Parameters

NameDetails

request

Required

Request

Return

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

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

abortKey

Required

string

Return

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

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:345

Parameters

NameDetails

queueKey

Required

string

Return

void

flush()

Preview

flush()

Description

Flush all available requests from all queues

Defined in dispatcher/dispatcher.ts:206

Return

Promise<void>

flushQueue()

Preview

flushQueue(queueKey)

Description

Method used to flush the queue requests

Defined in dispatcher/dispatcher.ts:176

Parameters

NameDetails

queueKey

Required

string

Return

Promise<void>

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

Preview

getIsActiveQueue(queueKey)

Description

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

Defined in dispatcher/dispatcher.ts:126

Parameters

NameDetails

queueKey

Required

string

Return

boolean

getQueue()

Preview

getQueue<Request>(queueKey)

Description

Return queue state object

Defined in dispatcher/dispatcher.ts:106

Parameters

NameDetails

queueKey

Required

string

Return

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

Parameters

NameDetails

queueKey

Required

string

Return

number

getQueuesKeys()

Preview

getQueuesKeys()

Description

Return all

Defined in dispatcher/dispatcher.ts:99

Return

string[]

getRequest()

Preview

getRequest<Request>(queueKey, requestId)

Description

Return request from queue state

Defined in dispatcher/dispatcher.ts:116

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

{
request: Request;
requestId: string;
retries: number;
stopped: boolean;
timestamp: number;
}

getRunningRequest()

Preview

getRunningRequest(queueKey, requestId)

Description

Get running request by id

Defined in dispatcher/dispatcher.ts:289

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

{
request: Request<any, any, any, any, any, any, AdapterType<any, any, any, any, any>, any, any, any>;
requestId: string;
timestamp: number;
}

getRunningRequests()

Preview

getRunningRequests(queueKey)

Description

Get currently running requests

Defined in dispatcher/dispatcher.ts:282

Parameters

NameDetails

queueKey

Required

string

Return

{
request: Request<any, any, any, any, any, any, AdapterType<any, any, any, any, any>, any, any, any>;
requestId: string;
timestamp: number;
}[]

hasRunningRequest()

Preview

hasRunningRequest(queueKey, requestId)

Description

Check if request is currently processing

Defined in dispatcher/dispatcher.ts:313

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:306

Parameters

NameDetails

queueKey

Required

string

Return

boolean

incrementQueueRequestCount()

Preview

incrementQueueRequestCount(queueKey)

Description

Add request count to the queueKey

Defined in dispatcher/dispatcher.ts:370

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:72

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:476

Parameters

NameDetails

storageElement

Required

QueueElementType<RequestInstance>

Return

Promise<void | QueueDataType<RequestInstance>>

setQueue()

Preview

setQueue<Request>(queueKey, queue)

Description

Set new queue storage value

Defined in dispatcher/dispatcher.ts:148

Parameters

NameDetails

queueKey

Required

string

queue

Required

QueueDataType<Request>

Return

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

Parameters

NameDetails

queueKey

Required

string

Return

void

startRequest()

Preview

startRequest(queueKey, requestId)

Description

Start particular request

Defined in dispatcher/dispatcher.ts:240

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:84

Parameters

NameDetails

queueKey

Required

string

Return

void

stopRequest()

Preview

stopRequest(queueKey, requestId)

Description

Stop particular request

Defined in dispatcher/dispatcher.ts:257

Parameters

NameDetails

queueKey

Required

string

requestId

Required

string

Return

void