@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
29 lines (27 loc) • 996 B
JavaScript
/**
* Waits for an asynchronous condition to be achieved.
* NOTE: This legacy utility is not a good replacement for proper angular techniques
*
* @param condition The function to determine if the desired state was achieved.
* @param errorMessage The message to fail the Jasmine test case with.
* @param duration The duration in milliseconds (ms) to wait for the desired condition.
*/
export function waitAsync(condition, errorMessage, duration = 1000) {
const timeLimit = Date.now() + duration;
return new Promise((resolve, reject) => {
const interval = setInterval(() => {
if (condition()) {
clearInterval(interval);
resolve();
return;
}
if (Date.now() >= timeLimit) {
clearInterval(interval);
reject(errorMessage);
fail(errorMessage);
return;
}
}, 10);
});
}
//# sourceMappingURL=wait-async.js.map