2020-05-20 16:33:19 +02:00
|
|
|
// @flow
|
|
|
|
|
import { printDeprecationWarning } from './helpers/errors';
|
|
|
|
|
|
2020-07-10 16:18:31 +02:00
|
|
|
type Thenable<T> = { then: (() => T) => mixed };
|
|
|
|
|
|
2020-05-20 16:33:19 +02:00
|
|
|
/**
|
|
|
|
|
* Wait for microtasks queue to flush
|
|
|
|
|
*/
|
2020-07-10 16:18:31 +02:00
|
|
|
export default function flushMicrotasksQueue<T>(): Thenable<T> {
|
2020-05-20 16:33:19 +02:00
|
|
|
printDeprecationWarning('flushMicrotasksQueue');
|
|
|
|
|
return flushMicroTasks();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 16:18:31 +02:00
|
|
|
export function flushMicroTasks<T>(): Thenable<T> {
|
|
|
|
|
return {
|
|
|
|
|
// using "thenable" instead of a Promise, because otherwise it breaks when
|
|
|
|
|
// using "modern" fake timers
|
|
|
|
|
then(resolve) {
|
|
|
|
|
setImmediate(resolve);
|
|
|
|
|
},
|
|
|
|
|
};
|
2020-05-20 16:33:19 +02:00
|
|
|
}
|