From ef56452ec93bda899325968c9ca0a99298e97fef Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 15 Feb 2021 15:16:30 -0800 Subject: [PATCH] feat(sleep): Adding sleep function to Util lib --- src/util.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/util.js b/src/util.js index 684a4c2..51dfc4c 100644 --- a/src/util.js +++ b/src/util.js @@ -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.