-
Notifications
You must be signed in to change notification settings - Fork 122
Closed
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels