Skip to content
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

feat: pass AbortSignal to effects and allow async signature #14753

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Dec 18, 2024

WIP

Copy link

changeset-bot bot commented Dec 18, 2024

🦋 Changeset detected

Latest commit: d2d1b20

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Minor

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

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@14753

@trueadm trueadm self-assigned this Dec 18, 2024
@trueadm
Copy link
Contributor Author

trueadm commented Jan 23, 2025

It occurred to me that rather than passing in the abort signal as an argument, we could instead capture it using a utility function const signal = getAbortSignal() that you can call inside reactions and then you can pass this to your promises and have the reaction clean it up for you. This also means we can treeshake out this logic if it's not used anywhere.

@briancray
Copy link

briancray commented Jan 23, 2025

Besides allowing the async signature (YES PLEASE), how is this different than the following? (I've been doing this pattern myself)

$effect(() => {
  const aborter = new AbortController()
  fetch('/foo', { signal: aborter.signal })
  return () => aborter.abort()
})

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.

2 participants