Iterator does not continue to flush messages after the event stream is closed
KamalAman opened this issue · 0 comments
KamalAman commented
The event iterator will immediately return the finialzer value as soon as the stop() callback is called. However, if there are still messages in the queue, we should continue to flush them.
const event = new EventEmitter();
const it = new EventIterator((next, stop, fail) => {
event.on('data', next);
event.on('close', stop);
}, (next, stop) => {
event.removeListener('data', next);
event.removeListener('close', next);
});
const iterator = it[Symbol.asyncIterator]();
event.emit('data', 'a');
event.emit('close');
event.emit('data', 'b');
const requests = Promise.all([
iterator.next(),
iterator.next(),
iterator.next(),
]);
const result = await requests;
// This will fail, we will never see the value for "a"
assert.deepEqual(result, [
{ value: 'a', done: false },
{ value: undefined, done: true },
{ value: undefined, done: true },
]);