Created
May 7, 2021 14:47
-
-
Save zipang/47197f55d76f0004402d048adc353fb6 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
/** | |
* Build a promise that resolve in `ms` milliseconds with the response provided | |
* NOTE: response may be a function, whose evaluation would be delayed by ms | |
* @param {Number} ms The delay to wait before resolving the Promise | |
* @param {Any} response The data to return after ms. | |
* @return {Promise} | |
*/ | |
export const delay = (ms, response) => | |
new Promise((resolve) => | |
setTimeout( | |
() => resolve(typeof response === "function" ? response() : response), | |
ms | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment