jacobheun / any-signal Goto Github PK
View Code? Open in Web Editor NEWCombines an array of AbortSignals into a single signal that is aborted when any signal is
License: Other
Combines an array of AbortSignals into a single signal that is aborted when any signal is
License: Other
Consider code in the README file:
const anySignal = require('any-signal')
const userController = new AbortController()
const timeoutController = new AbortController()
const combinedSignal = anySignal([userController.signal, timeoutController.signal])
combinedSignal.addEventListener('abort', () => console.log('Abort!'))
// Abort after 1 second
const timeoutId = setTimeout(() => timeoutController.abort(), 1000)
// The user or the timeout can now abort the action
await performSomeAction({ signal: combinedSignal })
clearTimeout(timeoutId)
After all the lines are executed, there are still event handlers attached to userController.signal
and timeoutController.signal
. There is no code that clears them. It all works fine if userController
and timeoutController
both are garbage collected after clearTimeout
.
Let's consider the following code, where an AbortController is long-lived, along with its AbortSignal.
class Loader {
shutdownController = new AbortController()
async load(id: string, options: { signal: AbortSignal }) {
const effectiveSignal = anySignal([this.shutdownController.signal, options.signal])
await doSomething(effectiveSignal)
return "Success!"
}
}
On every call to load
method, you'd add an event handler to this.shutdownController.signal
. It never gets removed, which leads to some minor but very constant memory leak, as well as some annoying warnings, like libp2p/js-libp2p#900
Are you open to PRs fixing this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.