-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add clear
method for a composite signal
#24
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
@jacobheun Hey, any critique on the PR? Let me share rationale for the change. In here, for example: https://github.com/libp2p/js-libp2p-delegated-content-routing/blob/master/src/index.ts#L200 as well as in other js-libp2p code you see that there is a permanent AbortController. On every function call it gets wrapped with any-signal. In a happy scenario, that leads to +1 event listener to
If something like explicit |
Hey @jacobheun - I'm Avi, PM at Ceramic. Wanted to expand on Sergey's 2nd point on user level warnings, we've seen this become a developer experience pain point - several forum and discord posts on this, e.g. [1] [2] [3] thanks in advance for juggling this on top of your EM work, appreciate you. |
@ukstv thanks for the nudge, I missed the PR as I was out on holiday in March. Have you tested this fix against js-libp2p to verify it fixes the problem there? I'll take a look at this in the mean time |
If you want to convert it to TS I don't have a problem with that. Overall adding If this gets you what you need, I'm fine with the changes as is and can ship a major release (given the types have changed). |
It's funny, I just came across this exact same problem. |
I have not really grokked how aegir works. What if I create a fully-functional repo with the code that I see is the most optimal route (breaking changes included, as Proxy has some perf penalty), and you transplant TS and tests into this very well-known package? The breaking change I mentioned is that maybe the return type of |
I have a small preference for returning a single value rather than a tuple as to me at least if feels a bit more idiomatic for js. If we're looking at this with fresh eyes, perhaps this module would return an extended We already do things like add extra methods to timeout-abort-controller so there's some precedent there. I am pro converting to TypeScript in general but I'd not want to block fixing this bug on that (or the above tbh), it's a bit of a show-stopper. |
Here my understanding of idiomatic JS says
For sure!! I just wanted to use a nice coincidence that we have smart people here participating in the discussion. Moving to TS, changing the interface are all topics adjacent but not blocking to this PR. All of that can be done separately. |
My thinking was that a function taking an
To be clear, my intention was not to pass controller instances outside of the calling function, more like: const controller = anySignal([...signals])
try {
return await onwardFunction(args, {
signal: controller.signal
})
} finally {
controller.clear()
} Not sure if |
Since we have enough of an agreement on this, I'm going to merge this, update the readme and cut a major release. Happy to continue conversations on future changes, but want to make sure folks aren't blocked on this. |
Published in 4.0.0 |
thanks Jacob and Alex! |
The IPNI and Reframe content routing modules here are really useful so I've broken them out into `@libp2p/ipni-content-routing` and `@libp2p/reframe-content-routing` for reuse elsewhere. I've also fixed a memory leak in both of them related to long-lived abort controllers, more info here: jacobheun/any-signal#24 This PR also updates the libp2p config as it was overriding some things that didn't need overriding. It also tries to tidy the types up a bit, adding deps for datastore/blockstore types instead of trying to pull them out of helia/libp2p types.
Not quite optimal, and I would prefer it all to be TypeScript code, yet here it goes. At least, as a provisionary PR open to critique.
Now
anySignal
function returnsAbortSignal
with a twist. If you callsignal.clear()
, it clears all the event handlers set up on the constituent AbortSignals. An example in #23 could be modified to not cause any memory leaks: