We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 89ec8f9 commit b9bf9faCopy full SHA for b9bf9fa
src/support/util.ts
@@ -100,3 +100,28 @@ export const leadingDebounce = <T extends (...args: any[]) => any>(
100
lastInvocation = Date.now();
101
} as T;
102
};
103
+
104
+export const waitForValue = <T>(
105
+ value: () => T,
106
+ interval = 100,
107
+ maxAttempts = 20,
108
+): Promise<T> =>
109
+ new Promise((resolve) => {
110
+ let attempts = 0;
111
112
+ const checkForValue = () => {
113
+ attempts++;
114
115
+ if (attempts > maxAttempts) {
116
+ return resolve(value());
117
+ }
118
119
+ if (value() === null) {
120
+ return setTimeout(checkForValue, 100);
121
122
123
+ resolve(value());
124
+ };
125
126
+ checkForValue();
127
+ });
0 commit comments