Skip to content

Don't emit end events after error events #547

Closed
@evansolomon

Description

@evansolomon

I always find it a little surprising/frustrating that Query objects (and maybe other types) can emit both 'error' and 'end' events. In most event emitters 'error' events are also effectively end events. I often end up with patterns like this.

var emitter = makeSomeEventEmitter()
emitter.on('error', callback)
emitter.on('end', function () {
  callback()
})

Because Query objects will emit both of those events in the case of an error, that becomes rather problematic and you end up having to do something like.

var emitter = makeSomeEventEmitter()
emitter.on('error', function (err) {
  callback(err)
  callback = function () {}
})
emitter.on('end', function () {
  callback()
})

Or maintain state about errors or something. In any case, it makes handling errors a little non-standard. I'd love to change the either 'error' or 'end' is emitted, but never both.

What do you think?

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