diff options
| author | Adam Soltys <[email protected]> | 2022-12-20 17:39:28 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-12-20 17:39:28 -0800 |
| commit | aa662369cc7a293d0be5f4d419543a51ad40a7bc (patch) | |
| tree | 8b53bd0ead2be327a00632014672e6b73e1dab10 /lib/utils.js | |
| parent | 9ebd4105fa412d16bfe58facc9ebb53847b3316a (diff) | |
| download | coinos-server-aa662369cc7a293d0be5f4d419543a51ad40a7bc.tar.gz coinos-server-aa662369cc7a293d0be5f4d419543a51ad40a7bc.zip | |
send user events
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js index 45e50243..7fdd10b3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -171,3 +171,11 @@ export const derivePayRequest = async ({ amount, memo, tip }) => { await ln.invoice(value ? `${value}sat` : "any", new Date(), memo, 360) ).bolt11; }; + +export const sleep = (n) => new Promise((r) => setTimeout(r, n)); +export const wait = async (f, s = 300, n = 1000) => { + let i = 0; + while (!(await f()) && i < s) (await sleep(n)) && i++; + if (i >= s) throw new Error("timeout"); + return f(); +}; |
