Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save max-mapper/7ce42ec0d841f40488d2 to your computer and use it in GitHub Desktop.

Select an option

Save max-mapper/7ce42ec0d841f40488d2 to your computer and use it in GitHub Desktop.

Revisions

  1. max-mapper revised this gist Oct 20, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,15 @@
    @mafintosh said most of this, I just wrote it down

    ## how to destroy/end streams in node >= 0.10

    - usually you call `.destroy()` if it has `.destroy`
    - if it doesnt have `.destroy` you are out of luck and the stream should upgrade to use e.g. newer `through2`
    - in request you call `.abort()` (this should get fixed to use `.destroy()`)
    - `.end()` tries to end the stream gracefully

    ### what about close, end
    ### what about close

    - usually no `.close` method exists except in FD backed streams (usually only `fs`). usually you would never call `.close()`
    - `.end()` tries to end the stream gracefully

    ### what about events

  2. max-mapper created this gist Oct 20, 2014.
    17 changes: 17 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    ## how to destroy/end streams in node >= 0.10

    - usually you call `.destroy()` if it has `.destroy`
    - if it doesnt have `.destroy` you are out of luck and the stream should upgrade to use e.g. newer `through2`
    - in request you call `.abort()` (this should get fixed to use `.destroy()`)

    ### what about close, end

    - usually no `.close` method exists except in FD backed streams (usually only `fs`). usually you would never call `.close()`
    - `.end()` tries to end the stream gracefully

    ### what about events

    - `finish` event is emitted when a stream ends nicely (e.g. `stream.end()`)
    - `close` and `error` events are emitted when a stream ends due to failure (e.g. `stream.destroy()`)
    - `end` is emitted when a readable stream has no more data
    - `end` in streams2 behaves more like a flush event, it only gets emitted when the data has been read from the readable