Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding unshift to add to front of the queue #11

Open
mattpodwysocki opened this issue Feb 10, 2016 · 5 comments
Open

Adding unshift to add to front of the queue #11

mattpodwysocki opened this issue Feb 10, 2016 · 5 comments

Comments

@mattpodwysocki
Copy link
Contributor

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?

@jbnicolai
Copy link

I'd definitely like to see this in 👍

@mattpodwysocki
Copy link
Contributor Author

@jbnicolai thanks, this should be pretty easy. @azproduction any interest in this?

@azproduction
Copy link
Collaborator

@mattpodwysocki looks good! Sort of jumpTheQueue() :)

@rops
Copy link

rops commented Jul 21, 2016

+1

@azproduction
Copy link
Collaborator

There are some pending changes in PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants