queueback
Callback queue system for optimizing HTTP requests by reducing potential duplicate requests. It basically allows you to queue callbacks based on HTTP method and URL.
Install
The module is released as ES6 module in the npm registry and can be installed using:
npm install --save queueback
API
Import and construct the queue using the following syntax:
; const queue = ;
add
Add a new callback to a method and URL specific queue. The method accepts the following arguments:
method
HTTP methodurl
URL that is being requestedfn
Callback to queue
The method will return a boolean that is an indication if we have queue in process for this callback so no new request should be made.
if queue return;
Please note that we guarantee that the callback is only called once and removed from the queue after execution.
remove
Remove an added callback from the queue. The method accepts the following arguments:
method
HTTP methodurl
URL that is being requestedfn
Callback to remove
{ throw 'I should never be called';} queue;queue;queue;
run
This allows you to execute all queued callbacks for the given method and URL combination. It accepts the following arguments.
method
HTTP methodurl
URL that is being requested
All of the other arguments are passed in to the queued callbacks.
queue;
all
Execute all the queued callbacks regardless of their method and URL combinations. All arguments are passed in to the queued callbacks.
queueall'Unable to authenticate with server';