Created
August 9, 2021 15:12
-
-
Save mfbx9da4/39df8ba49573f4455415a539f3b0b55b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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