Skip to content

Emits finish dispite still consuming #4

@piglovesyou

Description

@piglovesyou

The following code is a copy of an example in README plus finish event. I assumed the parallel transform emits finish after all data consumption but is didn't.

var stream = transform(10, function (data, callback) {
  setTimeout(function () {
    callback(null, data);
  }, Math.random() * 1000);
});

for (var i = 0; i < 10; i++) {
  stream.write('' + i);
}
stream.end();

stream.on('finish', function () {
  console.log('stream has finished');
});
stream.on('end', function () {
  console.log('stream has ended');
});

output

0
stream has finished
1
2
3
4
5
6
7
8
9
stream has ended

This is not pleasant especially when we use libs such as pump that calls a callback function depending on finish event.

It seems that it emits finish after all writable data is buffered instead of consumed.

This problem occurs also in parallel-stream module.

Also, when we do readable.pipe(parallelTransform).pipe(writable), the writable emits finish earlier than expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions