From aa662369cc7a293d0be5f4d419543a51ad40a7bc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 20 Dec 2022 17:39:28 -0800 Subject: send user events --- lib/utils.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/utils.js') 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(); +}; -- cgit v1.2.3