coapjs / node-coap

CoAP - Node.js style
MIT License
531 stars 154 forks source link

feat(agent): add `close` method #317

Closed JKRhb closed 2 years ago

JKRhb commented 2 years ago

This PR adds a close method to the Agent class that aborts all pending requests and resolves #312. To do so, a small bug is fixed in the abort method where the _msgInFlight hasn't been decremented when a request is cancelled.

An additional test is added to assert that the new method works as expected.

coveralls commented 2 years ago

Pull Request Test Coverage Report for Build 1473967935


Totals Coverage Status
Change from base Build 1427777898: 0.9%
Covered Lines: 562
Relevant Lines: 610

💛 - Coveralls
JKRhb commented 2 years ago

Ping @relu91 :)

JKRhb commented 2 years ago

I'm not coap expert but looking at the logic seems good. This should allow freeing all resources without waiting for responses :)

Thank you for the feedback! :) I added a last couple of changes to the method so that you can both provide an optional callback and listen for close events. This way the API is more similar to the one the CoAP server provides. I think if @Apollon77 could also have a look on it then the PR should be able to be merged :)

Apollon77 commented 2 years ago

Add that close before 1.0 or after? ;-)

Apollon77 commented 2 years ago

BTW: LGTM

JKRhb commented 2 years ago

Add that close before 1.0 or after? ;-)

Hmm, good question ;) I think we could already integrate it in 1.0 if this would be fine for you, but we could also put it into a separate minor (or patch?) release if you prefer.

Apollon77 commented 2 years ago

:-)