We found this bug from a report of our use of Zone.js in the Application Insights Node.js SDK causing generator functions to not get called: microsoft/ApplicationInsights-node.js#267
Native promises in Node.js support taking the result of a generator function as an argument to Promise.all, and wait for all yielded promises to complete. For example:
var generator = function*() {
yield Promise.resolve('1');
yield Promise.resolve('2');
yield Promise.resolve('3');
return;
};
Promise.all(generator()).then(val=>{
console.log(val);
})
will print out [ '1', '2', '3' ]. This breaks when including zone into the project.
The code for the ZoneAwarePromise.all method correctly uses a for-of loop to iterate its value (see
|
for (let value of values) { |
)
However, the compiled source, for zone-node at least, converts this into a standard for loop iterating an index against value.length (see
|
for (var _i = 0, values_2 = values; _i < values_2.length; _i++) { |
). This unfortunately doesn't work for generators, as they are iterable but don't have a defined length in advance.
The end result is executing the code sample above with zone.js included is getting the following printed out: []
We found this bug from a report of our use of Zone.js in the Application Insights Node.js SDK causing generator functions to not get called: microsoft/ApplicationInsights-node.js#267
Native promises in Node.js support taking the result of a generator function as an argument to
Promise.all, and wait for all yielded promises to complete. For example:will print out
[ '1', '2', '3' ]. This breaks when including zone into the project.The code for the
ZoneAwarePromise.allmethod correctly uses a for-of loop to iterate its value (seezone.js/lib/common/promise.ts
Line 273 in a66595a
However, the compiled source, for zone-node at least, converts this into a standard for loop iterating an index against
value.length(seezone.js/dist/zone-node.js
Line 893 in b9c0d9c
The end result is executing the code sample above with zone.js included is getting the following printed out:
[]