refactor: use Date.now() instead of +new Date() (#38901)

refactor: use Date.now()
This commit is contained in:
Milan Burda 2023-07-18 10:58:02 +02:00 committed by GitHub
parent 8874306dc0
commit 47951cc95b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 11 deletions

View file

@ -141,11 +141,11 @@ export async function repeatedly<T> (
opts?: { until?: (x: T) => boolean, timeLimit?: number }
) {
const { until = (x: T) => !!x, timeLimit = 10000 } = opts ?? {};
const begin = +new Date();
const begin = Date.now();
while (true) {
const ret = await fn();
if (until(ret)) { return ret; }
if (+new Date() - begin > timeLimit) { throw new Error(`repeatedly timed out (limit=${timeLimit})`); }
if (Date.now() - begin > timeLimit) { throw new Error(`repeatedly timed out (limit=${timeLimit})`); }
}
}