-1

I am trying to build "event" queue similar to this: https://stackoverflow.com/a/24932757/6385482

but without using any libraries (e.g. jQuery, Bluebird, Q)

Example: I have an array

var event = [func1, func2, func3];

...and i want to implement function called 'each' which itaretes 'event' and calls async function sequentially.

Sorry for my English.

Thank you for your help.

2
  • 1
    An example of what you wish to happen might be useful. Commented May 26, 2016 at 10:07
  • This question is really unclear. What are func1, func2, and func3? Are they already async, or are they sync and needing a wrapper? Do you want to wait to call func2 until func1's work is complete, or can they overlap? What have you looked at so far, what's worked, what hasn't worked? Commented May 26, 2016 at 10:09

1 Answer 1

0

thanks for your reply. Functions are already async, and I need to call func2 after func1 is done (they can't overlap)... I wrote my this function using Bluebird, here is an example:

var Bluebird = Promise.noConflict();

var items = [
    function () {
        return new Bluebird(function (resolve, reject) {
            console.log("promise1 pending");
            setTimeout(function () {
                console.log("promise1 fulfilled");
                resolve();
            }, 1000)
        })
    },
    function () {
        return new Bluebird(function (resolve, reject) {
            console.log("promise2 pending");
            setTimeout(function () {
                console.log("promise2 fulfilled");
                resolve();
            }, 500)
        })
    },
];

Bluebird.each(items, function (item, i) {
    return item();
});

This does exactly what I need, first calls "promise1 pending", then "promise1 fulfilled", then "promise2 pending" and "promise2 fulfilled"...

I tried to write this function with native Prosmises, but I couldn't figure out how.

Thank you for your help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.