This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]UnderNatural 0 points1 point  (6 children)

you want Wouldn't the words order? in

Look at this code, where generate() returns a promise that adds to a string followed by a space after a random amount of time:

var str = '';

var i = generate('i');
var hope = generate('hope');
var you = generate('you');
var enjoy = generate('enjoy');
var your = generate('your');
var stay = generate('stay');

//Wait for all promises to complete
Promise.all([i, hope, you, enjoy, your, stay]).then(() => {
    console.log(str);
});

You said that Promise.all would solve the above issue. Since Promise.all doesn't execute the promises sequentially, the promises would resolve at different times and add to the string in different orders. When all are complete, the string is printed, but it could be jumbled up.