Last active
May 25, 2022 21:45
-
-
Save MarekZeman91/d31093aa54cff35f8958a8d8f22c39d5 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 AbortCallback = (err: any) => void; | |
type SetAbort = (abortCallback: AbortCallback) => void; | |
export const delay = (ms: number, setAbort?: SetAbort) => { | |
return new Promise((resolve, reject) => { | |
const timeout = setTimeout(resolve, ms); | |
setAbort(err => { | |
clearTimeout(timeout); | |
reject(err); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment