Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

ZoneAwarePromise.all does not work properly with generators #892

Closed
OsvaldoRosado opened this issue Sep 5, 2017 · 2 comments · Fixed by #897
Closed

ZoneAwarePromise.all does not work properly with generators #892

OsvaldoRosado opened this issue Sep 5, 2017 · 2 comments · Fixed by #897

Comments

@OsvaldoRosado
Copy link

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: []

@JiaLiPassion
Copy link
Collaborator

@OsvaldoRosado , thank you for posting the issue. I will check it.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Sep 11, 2017
… angular), add downlevelIteration options when build zone-node
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Sep 11, 2017
… angular), add downlevelIteration options when build zone-node
mhevery pushed a commit that referenced this issue Sep 13, 2017
…f when build zone-node (#897)

* feat(compile): fix #892, upgrade to typescript 2.3.4(same with angular), add downlevelIteration options when build zone-node

* local test should also use downlevelIteration option
@OsvaldoRosado
Copy link
Author

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants