Skip to content

Instantly share code, notes, and snippets.

@mfbx9da4
Created August 9, 2021 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfbx9da4/39df8ba49573f4455415a539f3b0b55b to your computer and use it in GitHub Desktop.
Save mfbx9da4/39df8ba49573f4455415a539f3b0b55b to your computer and use it in GitHub Desktop.
type Fn = (signal: AbortController['signal']) => Promise<unknown>
/** or woman or non-binary for that matter */
export const createOneManQueue = () => {
let task: Promise<unknown> = Promise.resolve()
let abortController = new AbortController()
const enqueue = (fn: Fn) => {
abortController.abort()
abortController = new AbortController()
task.finally(() => {
task = fn(abortController.signal)
})
}
return { enqueue }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment