Skip to content

Conversation

@feross
Copy link
Member

@feross feross commented Jan 21, 2017

If the user calls:

client.stop()
client.destroy()

We should ensure that the final 'stopped' message reaches the tracker
server, even though the client will not get the response (because they
destroyed the client and no more events will be emitted).

If there are pending requests when destroy() is called, then a 1s timer
is set after which point all requests are forcibly cleaned up. If the
requests complete before the 1s timer fires, then cleanup happens right
away (so we're not stuck waiting for the 1s timer).

So, destroy() can happen one of three ways:

  • immediately, if no pending requests exist
  • after exactly 1s, if pending requests exist and they don't complete
    within 1s
  • less than 1s, if pending requests exist and they all complete before
    the 1s timer fires

If the user calls:

client.stop()
client.destroy()

We should ensure that the final 'stopped' message reaches the tracker
server, even though the client will not get the response (because they
destroyed the client and no more events will be emitted).

If there are pending requests when destroy() is called, then a 1s timer
is set after which point all requests are forcibly cleaned up. If the
requests complete before the 1s timer fires, then cleanup happens right
away (so we're not stuck waiting for the 1s timer).

So, destroy() can happen one of three ways:

- immediately, if no pending requests exist
- after exactly 1s, if pending requests exist and they don't complete
within 1s
- less than 1s, if pending requests exist and they all complete before
the 1s timer fires
@feross feross changed the title Final wait Wait up to 1s for pending requests before destroy() Jan 21, 2017
@feross
Copy link
Member Author

feross commented Jan 21, 2017

cc @CraigglesO

Copy link

@CraigglesO CraigglesO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IT WORKS!!!! I tested it using the current master branch of torrent discovery and I get an EVENT 3 back. Love it.

@feross
Copy link
Member Author

feross commented Jan 21, 2017

Since this is a large change, it would be nice to get a code review from one of the other maintainers before merge.

@CraigglesO
Copy link

Do you have a fax on how to become a contributor?

@feross
Copy link
Member Author

feross commented Jan 21, 2017

@feross
Copy link
Member Author

feross commented Jan 23, 2017

This PR has been open a few days so I'm going to merge it now. Post-merge feedback is still welcome.

@feross feross merged commit 3b463e4 into master Jan 23, 2017
@feross feross deleted the final-wait branch January 23, 2017 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants