rocket-connect / for-emit-of

Turn Node.js Events into Async Iterables.
https://www.npmjs.com/package/for-emit-of
MIT License
9 stars 2 forks source link

never ending emitter does not hang process #7

Closed Farenheith closed 4 years ago

Farenheith commented 4 years ago

I found an issue after the change I made for the timeout.

The Promise.race generated based without timeout control can't hang the process. This code, for example, should never finish, by common sense:

const {
    EventEmitter
} = require("events");
const forEmitOf = require("./dist");
const {
    sleep
} = require("./dist/sleep");

async function test() {
    const neverEmit = new EventEmitter();

    for await (const item of forEmitOf(neverEmit)) {
        console.log(`never will print ${item}`);
    }
}
test();

But node can't keep the process alive from the existence of a promise created base only in event listeners. If you run the code, you'll see that node just finish abruptly.