-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: flush microtask queue implementation (#1374)
* refactor: flush microtask queue implementation * refactor: code review changes * refactor: restore original flush function as legacy version * chore: rename file
- Loading branch information
1 parent
ce75f66
commit 918be8c
Showing
4 changed files
with
35 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { setImmediate } from './helpers/timers'; | ||
|
||
export function flushMicroTasks() { | ||
return new Promise((resolve) => setImmediate(resolve)); | ||
} | ||
|
||
/** | ||
* @deprecated To be removed in the next major release. | ||
*/ | ||
type Thenable<T> = { then: (callback: () => T) => unknown }; | ||
|
||
/** | ||
* This legacy implementation of `flushMicroTasks` is used for compatibility with | ||
* older versions of React Native (pre 0.71) which uses Promise polyfil. | ||
* | ||
* For users with older version of React Native there is a workaround of using our own | ||
* Jest preset instead the `react-native` one, but requiring such change would be a | ||
* breaking change for existing users. | ||
* | ||
* @deprecated To be removed in the next major release. | ||
*/ | ||
export function flushMicroTasksLegacy(): Thenable<void> { | ||
return { | ||
// using "thenable" instead of a Promise, because otherwise it breaks when | ||
// using "modern" fake timers | ||
then(resolve) { | ||
setImmediate(resolve); | ||
}, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters