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

Better Support for AbortControllers #2

Open
loreanvictor opened this issue Mar 15, 2023 · 0 comments
Open

Better Support for AbortControllers #2

loreanvictor opened this issue Mar 15, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@loreanvictor
Copy link
Owner

Right now, the syntax for supporting abort controllers is a bit clunky:

let ctrl = new AbortController()

const data = observe(async $ => {
  const res = await fetch('https://my.api/?q=' + $(input), {
    signal: ctrl.signal
  })

  return await res.json()
}, () => {
  ctrl.abort()
  ctrl = new AbortController()
})

However, creating AbortControllers is not cheap, and so should only be done when the user demands it. Subsequently, the only way for handling this is to increase API surface and provide support for abortable observations:

const data = observeAbortable(async ($, singal) => {
  return await fetch('https://my.api/?q=' + $(input), { signal })
})

The observe() function can decide to include the signal or not based on the number of arguments provided in the expression, but this should be further investigated as it might be a bit clunky:

const data = observe(async ($, singal) => {
  return await fetch('https://my.api/?q=' + $(input), { signal })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant