Adding unshift to add to front of the queue
See original GitHub issueI’m a developer on the Thali Project at Microsoft, and we’d love to use your library. We currently have our own implementation of a PromiseQueue
which has associated tests in testPromiseQueue.js
.
What we’re missing from this implementation is the ability to add items to the beginning of the queue as we file things in priority order. We’d rather just use something simple instead of a priority queue, so your project is perfect. All we’d want to add is something like the following?
/**
* @param {Function} promiseGenerator
* @return {LocalPromise}
*/
Queue.prototype.unshift = function (promiseGenerator) {
var self = this;
return new LocalPromise(function (resolve, reject, notify) {
// Do not queue to much promises
if (self.queue.length >= self.maxQueuedPromises) {
reject(new Error('Queue limit reached'));
return;
}
// Add to queue
self.queue.unshift({
promiseGenerator: promiseGenerator,
resolve: resolve,
reject: reject,
notify: notify || noop
});
self._dequeue();
});
};
If you are amenable to adding it, with the choice of your name of course, then we’d happily file the PR with any documentation changes and tests included. Thoughts?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Array.prototype.unshift() - JavaScript - MDN Web Docs
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
Read more >JavaScript Array unshift() Method - W3Schools
The unshift() method adds new elements to the beginning of an array. The unshift() method overwrites the original array. See Also: The Array...
Read more >JavaScript Array unshift() - Prepend One or More Elements to ...
In this tutorial, you'll learn how to use the JavaScript Array unshift() method to add one or more elements to the beginning of...
Read more >Add new elements at the beginning of an array using JavaScript
Adding new elements at the beginning of the existing array can be done by using the Array unshift() method. This method is similar...
Read more >array_unshift - Manual - PHP
array_unshift — Prepend one or more elements to the beginning of an array ... You can preserve keys and unshift an array with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There are some pending changes in PR.
+1