Skip to content

Instantly share code, notes, and snippets.

@AirStair
Created March 2, 2022 22:19
Show Gist options
  • Save AirStair/302fd600a052b5dbfe76b7b07d1f30e1 to your computer and use it in GitHub Desktop.
Save AirStair/302fd600a052b5dbfe76b7b07d1f30e1 to your computer and use it in GitHub Desktop.
function promiseAbortController (asyncFunction) {
let controller = {}
controller.signal = new Promise((resolve, reject) => {
controller.abort = reject
asyncFunction().then(resolve)
})
return controller
}
const { signal, abort } = promiseAbortController(async () => {})
abort()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment