Skip to content

Instantly share code, notes, and snippets.

@MarekZeman91
Last active May 25, 2022 21:45
Show Gist options
  • Save MarekZeman91/d31093aa54cff35f8958a8d8f22c39d5 to your computer and use it in GitHub Desktop.
Save MarekZeman91/d31093aa54cff35f8958a8d8f22c39d5 to your computer and use it in GitHub Desktop.
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