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

ZoneAwarePromise.all does not work properly with generators #892

Closed
@OsvaldoRosado

Description

@OsvaldoRosado

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions