Created
January 21, 2023 20:09
-
-
Save tresorama/5cf918c212724b3c71f695a541f9d08b to your computer and use it in GitHub Desktop.
sleep
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
/** | |
* Generic setTimeout implementation with Promise, used for wait some time then do something. | |
* Generally used for simulating async operation execution time while developing. | |
* @param time Time to wait for, in ms. | |
* @param returnValue Optional. What will be returned from the promise. | |
* @returns Promise that always resolve with "returnValue" after "time" ms. | |
*/ | |
export const sleep = <T,>(time: number, returnValue?: T) => new Promise<T | undefined>(resolve => setTimeout(() => resolve(returnValue), time)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment