Skip to content

event stream destruction #302

@boneskull

Description

@boneskull

There doesn't seem to be any way to stop an EventStream from continually long-polling once started, short of killing the Node.js process.

In Node.js v8.x or later I think you want to implement the Readable stream's _destroy() (much like you would with _read()) method.

For Node.js pre-v8.x, generally it looks like you're going to want to wrap Readable#destroy(). So a solution might look like this:

EventStream.prototype._destroy = function() {
  // if this is v8.x+ and `EventStream#destroy()` was called, then 
  // `this.destroyed` will be true.  if it isn't, then call it,
  // since we probably got here via `MyStream#abort()`.
  // `Readable#destroy()` sets `this.destroyed` to `true`.
  if (!this.destroyed) {
    this.destroy();
  }
  // shut down long polling
});

EventStream.prototype.abort = EventStream.prototype._destroy;

My use-case: I'm implementing event streams in a Node-RED addon, which will otherwise leak memory and resources.

Hopefully this sounds OK; I have an implementation and tests which I'll send as soon as tomorrow.

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