-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: pass AbortSignal to effects and allow async signature #14753
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
🦋 Changeset detectedLatest commit: d2d1b20 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
It occurred to me that rather than passing in the abort signal as an argument, we could instead capture it using a utility function We should also supply a way of making it easy to compose in other contexts too: const abort = withAbortSignal(() => {
///
}); |
|
Besides allowing the async signature (YES PLEASE), how is this different than the following? (I've been doing this pattern myself) |
|
Just wanted to add this pattern for event handlers - $effect(() => {
const controller = new AbortController()
window.addEventListener('resize', handleResize, {
signal: controller.signal,
})
window.addEventListener('hashchange', handleHashChange, {
signal: controller.signal,
})
window.addEventListener('storage', handleStorageChange, {
signal: controller.signal,
})
return () => {
// Calling `.abort()` removes ALL event listeners
// associated with `controller.signal`. Gone!
controller.abort()
}
} |
We might want to use this signal in other places other than effects. |
|
What happens to variables that are not caught by the synchronous execution of $effect? |
|
I'm curious why this is closed and if there is a good or better place to track async primitives? |
WIP