Last active
October 21, 2020 17:07
-
-
Save antomor/70fd5c22254d2bbb0abc146406e0cebe to your computer and use it in GitHub Desktop.
It includes a wait function that returns a promise to be waited, it is also possible to specify a cancelToken, to stop waiting.
This file contains hidden or 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
const wait = (milliSeconds) => { | |
return new Promise((resolve) => setTimeout(() => resolve(), milliSeconds)); | |
}; | |
wait(200).then(() => { | |
// your code | |
}); | |
// async/await context | |
await wait(200); | |
//your code | |
const wait = (milliSeconds, cancelToken) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(), milliSeconds); | |
cancelToken.then(() => reject()) | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment