Adding a mechanism to postpone DB access before the DB is ready.
This commit is contained in:
1 parent
a36c8a28a4
commit
5ca12b6780
5 files changed
+67
-7
No files matched your search
@@ -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);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user