Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async generator yielding undefined values #2711

Closed
jedel1043 opened this issue Mar 21, 2023 · 0 comments
Closed

Async generator yielding undefined values #2711

jedel1043 opened this issue Mar 21, 2023 · 0 comments
Labels
bug Something isn't working execution Issues or PRs related to code execution
Milestone

Comments

@jedel1043
Copy link
Member

jedel1043 commented Mar 21, 2023

Taken from https://github.com/tc39/test262/blob/9704d7f22f6342d6c4753ab9a8d62d6725de8c4e/test/language/expressions/await/for-await-of-interleaved.js

To Reproduce

const actual = [];
const iterations = 3;

async function* naturalNumbers(start) {
    let current = start;
    while (current > 0) {
        yield Promise.resolve(current--);
    }
}

async function trigger() {
    for await (const num of naturalNumbers(iterations)) {
        actual.push('A' + num);
    }
}

async function checkAssertions() {
    console.log(actual) // should print P6,P5,A3,P4,P3,A2,P2,P1,A1,P0
}

function countdown(counter) {
    actual.push('P' + counter);
    if (counter > 0) {
        return Promise.resolve(counter - 1).then(countdown);
    } else {
        checkAssertions();
    }
}

trigger();
countdown(iterations * 2);

Expected behavior
Print P6,P5,A3,P4,P3,A2,P2,P1,A1,P0

Current behavior
Prints P6,P5,A3,P4,P3,Aundefined,P2,P1,A2,P0

@jedel1043 jedel1043 added bug Something isn't working execution Issues or PRs related to code execution labels Mar 21, 2023
@jedel1043 jedel1043 added this to the v0.17.0 milestone Mar 21, 2023
@bors bors bot closed this as completed in 54695cc Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant