MCPcopy Index your code
hub / github.com/Expensify/App / waitForBatchedUpdates

Function waitForBatchedUpdates

tests/utils/waitForBatchedUpdates.ts:14–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12 * waitForBatchedUpdates().then(...)
13 */
14const waitForBatchedUpdates = (): Promise<void> =>
15 new Promise((outerResolve) => {
16 // We first need to exhaust the microtask queue, before we schedule the next task in the macro-task queue (setTimeout).
17 // This is because we need to wait for all async onyx operations to finish, as they might schedule other macro-tasks,
18 // and we want those tasks to run before our scheduled task.
19 // E.g. this makes the following code work for tests:
20 //
21 // Onyx.merge(...)
22 // return waitForBatchedUpdates().then(...);
23 //
24 // Note: Ideally, you'd just await the Onyx.merge promise.
25
26 new Promise((innerResolve) => {
27 setImmediate(() => {
28 innerResolve("Flush all micro tasks that pushed by using '.then' method");
29 });
30 }).then(() => {
31 if (getIsUsingFakeTimers()) {
32 jest.runOnlyPendingTimers();
33 outerResolve();
34 return;
35 }
36 setTimeout(outerResolve, 0);
37 });
38 });
39
40export default waitForBatchedUpdates;

Calls

no outgoing calls

Tested by 4

setupDomainFeedFunction · 0.68
setupManageTeamScenarioFunction · 0.68