Promise.all: Order of resolved values

Looking at MDN it looks like the values passed to the then() callback of Promise.all contains the values in the order of the promises. For example:

var somePromises = [1, 2, 3, 4, 5].map(Promise.resolve);
return Promise.all(somePromises).then(function(results) {
  console.log(results) //  is [1, 2, 3, 4, 5] the guaranteed result?
});

Can anybody quote a spec stating in which order values should be in?

PS: Running code like that showed that this seems to be true although that is of course no proof - it could have been coincidence.

Answers


Following the spec you linked to, Promise.all(iterable) takes an iterable (that is, an object that supports the Iterator interface) as a parameter and later on calls PerformPromiseAll( iterator, constructor, resultCapability) with it, where the latter loops over iterable using IteratorStep(iterator). This means that if if the iterable you pass in to Promise.all() is strictly ordered, they will still be ordered once passed in.

Resolving is implemented via Promise.all() Resolve where each resolved promise has an internal [[Index]] slot, which marks the index of the promise in the original input.

All this means that the output is strictly ordered as the input as long as the input is strictly ordered (for example, an array).


Need Your Help

Load related entity's from jump table

vb.net entity-framework-4 entity-relationship

I have a jump table to relate the Customers and the contact, I want to load all contacts by a customer name. What is the best way to do that?

Changing the format of excel turns file in to insane size

excel vba excel-vba

I Just change format of sheets using a vba code and the file turns insanely large and increases by ~200 MB. If I do it using excel interface , nothing like this happens but I want to use the code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.