unify usage of sleepAsync and add tests
The tests mock JS setTimeout API. However promise.resolve() is not working without flushing the promise queue (which could be done just by awaiting Promise.resolve()), similar issue has been discussed in facebook/jest#2157.
This commit is contained in:
5
src/infrastructure/Threading/AsyncSleep.ts
Normal file
5
src/infrastructure/Threading/AsyncSleep.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export type SchedulerType = (callback: (...args: any[]) => void, ms: number) => void;
|
||||
|
||||
export function sleepAsync(time: number, scheduler: SchedulerType = setTimeout) {
|
||||
return new Promise((resolve) => scheduler(() => resolve(undefined), time));
|
||||
}
|
||||
Reference in New Issue
Block a user