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: introduce abort() method #734

Merged
merged 2 commits into from Mar 17, 2024
Merged

Conversation

antongolub
Copy link
Contributor

closes #527

const p1 = $`sleep 9999`
setTimeout(() => p.abort(), 100)

const ac = new AbortController()
const p2 = $({ ac })`sleep 9999`
setTimeout(() => ac.abort(), 100)
  • Tests pass

@antonmedv antonmedv merged commit fa4a7b4 into google:main Mar 17, 2024
10 checks passed
@ftoh
Copy link

ftoh commented Apr 6, 2024

Why support ac instead of signal, for which JavaScript has methods to work with?

const p1 = $({ signal: AbortSignal.timeout(100) })`sleep 9999`
 
// and

const ac = new AbortController()
const p2 = $({ 
  signal: AbortSignal.any(AbortSignal.timeout(1000), ac.signal)
})`sleep 9999`

button.addEventListener('click', () => {
  ac.abort()
})

@antongolub antongolub deleted the add-abort-api branch April 6, 2024 05:05
@antongolub
Copy link
Contributor Author

antongolub commented Apr 6, 2024

Reasonable, I'll add signal shortcut too.

antongolub added a commit to antongolub/zx that referenced this pull request Apr 6, 2024
@antonmedv
Copy link
Collaborator

Let’s drop ac in flavor of signal?

antonmedv pushed a commit that referenced this pull request Apr 6, 2024
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.

Feature: Abort controller support
3 participants