diff --git a/CHANGELOG.md b/CHANGELOG.md index eb58d3464..63abd9056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,10 @@ * `DashModel|GroupingChooserModel|FilterChooserModel|PanelModel|TabContainerModel.provider` * `PersistenceProvider.clearRaw()` * Renamed `ZoneGridModelPersistOptions.persistMappings`, adding the trailing `s` for consistency. -* Updated `JsonBlobService.listAsync` to inline `loadSpec` with all other args in a single object. +* Changed signature of `JsonBlobService.listAsync()` to inline `loadSpec` with all other args in a + single options object. +* Changed signature of `waitFor()` to take its optional `interval` and `timeout` arguments in a + single options object. ### 🎁 New Features diff --git a/promise/Promise.ts b/promise/Promise.ts index 245047df3..99fd436e9 100644 --- a/promise/Promise.ts +++ b/promise/Promise.ts @@ -121,21 +121,20 @@ export function wait(interval: number = 0): Promise { } /** - * Return a promise that will resolve after a condition has been met, polling at the specified - * interval. - * - * @param condition - function that should return true when condition is met + * Return a promise that will resolve after a condition has been met, or reject if timed out. + * @param condition - function returning true when expected condition is met. * @param interval - milliseconds to wait between checks (default 50). Note that the actual time * will be subject to the minimum delay for `setTimeout()` in the browser. * @param timeout - milliseconds after which the Promise should be rejected (default 5000). */ export function waitFor( condition: () => boolean, - interval: number = 50, - timeout: number = 5 * SECONDS + {interval = 50, timeout = 5 * SECONDS}: {interval?: number; timeout?: number} = {} ): Promise { - const startTime = Date.now(); + if (!isNumber(interval) || interval <= 0) throw new Error('Invalid interval'); + if (!isNumber(timeout) || timeout <= 0) throw new Error('Invalid timeout'); + const startTime = Date.now(); return new Promise((resolve, reject) => { const resolveOnMet = () => { if (condition()) {