feat(sleep): Adding sleep function to Util lib

This commit is contained in:
Chris Troutner
2021-02-15 15:16:30 -08:00
parent b3be470c0e
commit ef56452ec9
+24
View File
@@ -150,6 +150,30 @@ class Util {
}
}
/**
* @api util.sleep() sleep()
* @apiName sleep
* @apiGroup Util
* @apiDescription Promise-based delay.
* Expects an integer as input, which represents milliseconds. This function
* will return a Promise that resolves that many milliseconds later.
*
*
* @apiExample Example usage:
* (async () => {
* try {
* const tenSeconds = 10000
* await bchjs.Util.sleep(tenSeconds)
* } catch(error) {
* console.error(error)
* }
* })()
*
*/
sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
/**
* @api util.validateAddress() validateAddress()
* @apiName Validate Address.