Adding a mechanism to postpone DB access before the DB is ready.

This commit is contained in:
vdv committed 2022-12-25 21:37:59 +01:00
1 parent a36c8a28a4
commit 5ca12b6780
5 files changed
+67 -7

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
// See https://stackoverflow.com/questions/22125865/how-to-wait-until-a-predicate-condition-becomes-true-in-javascript
export const sleep = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
export const until = async (fn: any, ms: number = 0) => {
while (!fn()) {
await sleep(ms);
}
};