@asgardeo/auth-spa 0.4.11 → 0.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -215,4 +215,19 @@ export class SPAUtils {
215
215
 
216
216
  await new Promise((resolve) => setTimeout(resolve, timeToWait * 1000));
217
217
  }
218
+
219
+ /**
220
+ * Waits for a condition before executing the rest of the code in non-blocking manner.
221
+ *
222
+ * @param condition {() => boolean} - Condition to be checked.
223
+ * @param timeout {number} - Time in miliseconds.
224
+ */
225
+ public static until = (
226
+ condition: () => boolean,
227
+ timeout: number = 500
228
+ ) => {
229
+ const poll = (done) => (condition() ? done() : setTimeout(() => poll(done), timeout));
230
+
231
+ return new Promise(poll);
232
+ };
218
233
  }