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.
IxJS version: 5.0.0
Code to reproduce:
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.