We encountered the following synchronization problem while using .each(). We couldn't figure out if it is intentionally design like this or a bug based on the documentation, so would like to get any insight from you guys:
// Expect: 1 2 3 4 5
// Actual: 1 3 4 5 2
console.log(1);
Promise.resolve([3,4,5])
.each(function(v) {
console.log(v);
});
console.log(2);
It seems like the function get executed synchronously. The same problem happens to .filter() function too. In the contrary , the following snippet get executed expectedly:
// Expect: 1 2 [3 4 5]
// Actual: 1 2 [3 4 5]
console.log(1);
Promise.resolve([3,4,5])
.then(function(v) {
console.log(v);
});
console.log(2);
We encountered the following synchronization problem while using
.each(). We couldn't figure out if it is intentionally design like this or a bug based on the documentation, so would like to get any insight from you guys:It seems like the function get executed synchronously. The same problem happens to
.filter()function too. In the contrary , the following snippet get executed expectedly: