stream: ensure finish is emitted in next tick
When using end()
it was possible for 'finish'
to be emitted synchronously causing incorrect behaviour and subtle bugs.
This is an edge case not usually encountered since a write()
is usually pending and will be the one to initiate finishMaybe()
through afterWrite
which is always async.
This PR also cause _destroy()
to be called in nextTick when autoDestroy
is enabled during this edge case.
NOTE: 'prefinish'
must be synchronous in order to not break Transform
. I've got another PR in the works to sort this out.
Should probably be semver major.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines