I got a situation where the timeout is thrown even though the duration between event emission is lesser than it.
This issue occurs because of the combination of the delay of the "for await of" operation and the timeout itself.
I was able to create a test case where this issue happens
it("should not throw timeout for delays caused by the 'for await of' using the generated Async Iterable", async () => {
const emitter = new EventEmitter();
const iterator = forEmitOf<{ message: string }>(emitter, {
firstEventTimeout: 100,
inBetweenTimeout: 100,
});
setTimeout(async () => {
emitter.emit("data", { message: "test1" });
emitter.emit("data", { message: "test2" });
await sleep(80);
emitter.emit("data", { message: "test3" });
await sleep(80);
emitter.emit("data", { message: "test4" });
emitter.emit("end");
}, 10);
let result = "";
for await (const chunk of iterator) {
await sleep(50);
result += chunk.message;
}
expect(result).to.equal("test1test2test3test4");
});
I got a situation where the timeout is thrown even though the duration between event emission is lesser than it.
This issue occurs because of the combination of the delay of the "for await of" operation and the timeout itself. I was able to create a test case where this issue happens