-
Notifications
You must be signed in to change notification settings - Fork 123
destroyable EventStreams; closes #302 #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Verified that @boneskull has signed the CLA. Thanks for the pull request! |
Pull Request Test Coverage Report for Build 1364
💛 - Coveralls |
a353ac5
to
8e1168d
Compare
@boneskull Overall the implementation looks good to me, but it looks like tests aren't passing on Node.js versions before 8.x — you'll need to ensure your code works correctly for versions all the way back to Node.js 4.0.0 |
8e1168d
to
48c8aa4
Compare
The coverage % decreased because this PR adds more covered LoC to the project. I don't love how Coveralls calculates that... |
@mattwiller The failures have been fixed on Travis-CI |
lib/event-stream.js
Outdated
if (!this.destroyed) { | ||
/* istanbul ignore else */ | ||
if (typeof this.destroy === 'function') { | ||
this.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Node.js Stream docs say that _destroy()
is called by destroy()
— why call back into destroy()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because destroy
was not added until v8 of Node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(so if you called abort
you might as well have called destroy
if it exists. this is moot if I just conditionally add the method)
lib/event-stream.js
Outdated
* @returns {void} | ||
* @public | ||
*/ | ||
EventStream.prototype.abort = EventStream.prototype._destroy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit undesirable to have two different methods to call depending on which version of Node.js the user is running. Is it possible to check if EventStream.prototype.destroy
already exists and conditionally add/polyfill it if it doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we could do that.
4334ae6
to
e128da5
Compare
@mattwiller Build needs retry; Node.js v9 didn't seem to start. |
lib/event-stream.js
Outdated
}; | ||
|
||
// backwards-compat for Node.js pre-v8.0.0 | ||
if (!(typeof Readable.destroy === 'function')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to check against Readable.prototype.destroy
here — this condition as written will always include the polyfill. Also, using !==
might be more readable than !(... === ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad
e128da5
to
e3f1622
Compare
- add reference to long-polling timer on class - add `EventStream` method `_destroy()`, which clears any existing long-polling timer, and deletes it. Destroys stream if not already destroyed. Implements `Readable#_destroy` in Node.js v8.x and newer. - add polyfill for `Readable#destroy`, which isn't present pre-Node.js-v8.x - add checks for `destroyed` stream state which effectively abort various tasks in `EventStream` - consolidate long-polling retry logic into its own private method, `EventStream#retryLongPoll()`. - add tests for logic changes - add note in docs
e3f1622
to
63fc449
Compare
@mattwiller addressed your latest comments |
@mattwiller Do you need anything else from me here? |
@mattwiller Possible to release this soon? |
@boneskull We're looking to push out a release later this week! |
EventStream
method_destroy()
, which clears any existinglong-polling timer, and deletes it. Destroys stream if not already
destroyed. Implements
Readable#_destroy
in Node.js v8.x and newer.EventStream
methodabort()
, an alias for_destroy()
, whichis not called via
EventStream#destroy()
in pre-Node.js-v8.x. Anyversion can use this method;
_destroy()
is private.destroyed
stream state which effectively abortvarious tasks in
EventStream
EventStream#retryLongPoll()
.It'd be helpful to have an integration test (without use of Sinon's fake timers) which asserts a destroyed stream doesn't still have tasks in the event loop. If it does, such a test should hang--ostensibly due to the infinite recursion--because of Mocha's v4.x+ behavior.
Originally, I discovered this problem when writing some test code which consumes an
EventStream
. I could determine that this implementation was correct, because my test code was no longer hanging indefinitely. 😄