Skip to content

In writable stream, should we always set state.errorEmitted to true when executing stream.emit('error')? #18181

Closed
@MoonBall

Description

@MoonBall

I have read the source code of lib/_stream_writable.js. I have a doubt about the meaning of state.errorEmitted.

Why do we set state.errorEmitted to true in some situations of stream.emit('error'), but doesn't set it in other situations. Moreover, it doesn't achieve emitting 'error' event only one time. For example, as shown below, the code will emit 'error' event two times :

const { Writable } = require('stream');

w = new Writable();
w.on('error', error => {
  console.log('on error.', error);
});
w.write(null);
w.write(null);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions