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

merge function can cause unhandled rejected promise condition #353

Closed
andreasdamm opened this issue Apr 19, 2023 · 0 comments
Closed

merge function can cause unhandled rejected promise condition #353

andreasdamm opened this issue Apr 19, 2023 · 0 comments

Comments

@andreasdamm
Copy link

IxJS version: 5.0.0

Code to reproduce:

import { AsyncSink, merge, empty } from "ix/asynciterable/index.js";
async function main() {
    const s = new AsyncSink();
    s.write(42);
    s.error(new Error("error"));
    const m = merge(s, empty());
    for await (const _ of m) {
        break;
    }
}
try {
    await main();
}
catch (e) { }

Expected behavior:
Process runs to completion with success exit code and no output

Actual behavior:
Process exits prematurely with error exit code due to unhandled promise rejection

Additional information:
The [Symbol.asyncIterator] function of MergeAsyncIterable creates a new promise and then yields execution. Should the promise be rejected before execution resumes then no continuation is wired up for that promise causing an unhandled promise rejection which with newer versions of nodejs causes the entire process to exit.

The fix is to first yield the value and then create the new promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant