question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding unshift to add to front of the queue

See original GitHub issue

I’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:open
  • Created 8 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
azproductioncommented, Jan 29, 2018

There are some pending changes in PR.

1reaction
ropscommented, Jul 21, 2016

+1

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found