new DelayQueue(delayFn)
Example
var DelayQueue = require("dsjslib").DelayQueue
var dq=new DelayQueue(function(task){
return task.schedule - Date.now();
})
Parameters:
Name | Type | Description |
---|---|---|
delayFn |
DelayQueue~userDelayFn | A user provided delay function |
- Source:
Extends
Methods
-
clear()
-
Cleanup and remove all elements from the queue
- Inherited From:
- Source:
-
entries() → {Array}
-
- Inherited From:
- Source:
Returns:
Returns array of elements in the queue. Ordering of those elements in undefined
- Type
- Array
-
offer(obj) → {PriorityQueue}
-
Parameters:
Name Type Description obj
Insert the object in queue. Re-heapifies the queue.
- Inherited From:
- Source:
Returns:
this
- Type
- PriorityQueue
-
peek() → {*}
-
Returns, without removing, the element at the head of the queue
- Inherited From:
- Source:
Returns:
Returns the element at the head of the queue . The head of this queue is the maximum element with respect to the specified ordering. If multiple elements are tied for max value, the head is one of those elements -- ties are broken arbitrarily.
- Type
- *
-
poll() → {*}
-
Returns and removes the element at the head of the queue . Re-heapifies the queue.. The head of this queue is the element whose delay expires furthest in the past if there is no such element with negative or zero expired delay, this method returns null
- Source:
Returns:
Element whose delay expires furthest in the past
- Type
- *
-
size() → {Number}
-
- Inherited From:
- Source:
Returns:
number of elements in the queue
- Type
- Number
-
take(callback)
-
Retrieve and remove the head of queue when it expires. Unlike poll() which returns immediately with either null or the head element (if it has expired), this method registers the user callback which will be invoked when the an item is available i.e. delay has expired.
Parameters:
Name Type Description callback
DelayQueue~onAvailableCb - Source:
Type Definitions
-
onAvailableCb(err, item)
-
The callback is asynchronous and takes two arguments err and item err contains any error encountered and item is the head object once its available.
Parameters:
Name Type Description err
Error if any, null otherwise
item
* head element once available
- Source:
-
userDelayFn(queueElement)
-
A user provided delay function for ordering of elements in queue
Parameters:
Name Type Description queueElement
* - Source:
Returns:
The function should return a negative integer, zero, or a positive integer depending on how much time remains before the item is expired. The argument to the function is the item for which delay is being queried