aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js8
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();
+};