dexie-react-hooks
Version:
React hooks for reactive data fetching using Dexie.js
23 lines (21 loc) • 555 B
text/typescript
import { assert } from 'qunit';
export function waitTilOk(
evaluateCondition: () => boolean,
description: string,
timeout = 2000
) {
return new Promise((resolve, reject) => {
const start = Date.now();
const interval = setInterval(() => {
if (evaluateCondition()) {
clearInterval(interval);
assert.ok(true, description);
resolve(true);
} else if (Date.now() - start > timeout) {
clearInterval(interval);
assert.ok(false, description);
resolve(false);
}
}, 10);
});
}