Closed ronag closed 4 years ago
Thanks! That’s helpful. This is my first big experience with custom streams. Any good resource on how to properly write them? The core source code is kinda awful.
@paulmillr: Np.
The streams docs are probably the best resources. I would recommend to read the latest version on github https://github.com/nodejs/node/tree/master/doc which has a lot of recent improvements not available on nodejs.org. Streams are unfortunately quite difficult with a lot of edge cases. However, Node and myself are working on improving both the code and the docs.
readdirp
is a quite heavily used lib (by myself as well through chokidar
). If you need help reviewing streams related stuff feel free to ping me.
Fixes some minor streams related issues.
destroy(err)
to ensure'error'
is only emitted once and in the next tick. Also ensures internal stream state is properly set and the'close'
and 'error'
events are emitted in the correct order and tick.destroyed
instead ofreadable
.autoDestroy
to ensure stream is destroyed properly and emits'close'
once completed.'error'
that occurs afterdestroyed
but before'close'
.Readable.destroy
. Doing so can have unforeseen consequences.This ensures that it behaves like a "proper" stream and follows expectations.