MCPcopy
hub / github.com/react/react / recursivelyFlushAsyncActWork

Function recursivelyFlushAsyncActWork

packages/react/src/ReactAct.js:271–308  ·  view source on GitHub ↗
(
  returnValue: T,
  resolve: T => mixed,
  reject: mixed => mixed,
)

Source from the content-addressed store, hash-verified

269}
270
271function recursivelyFlushAsyncActWork<T>(
272 returnValue: T,
273 resolve: T => mixed,
274 reject: mixed => mixed,
275) {
276 if (__DEV__) {
277 // Check if any tasks were scheduled asynchronously.
278 const queue = ReactSharedInternals.actQueue;
279 if (queue !== null) {
280 if (queue.length !== 0) {
281 // Async tasks were scheduled, mostly likely in a microtask.
282 // Keep flushing until there are no more.
283 try {
284 flushActQueue(queue);
285 // The work we just performed may have schedule additional async
286 // tasks. Wait a macrotask and check again.
287 queueMacrotask(() =>
288 recursivelyFlushAsyncActWork(returnValue, resolve, reject),
289 );
290 return;
291 } catch (error) {
292 // Leave remaining tasks on the queue if something throws.
293 ReactSharedInternals.thrownErrors.push(error);
294 }
295 } else {
296 // The queue is empty. We can finish.
297 ReactSharedInternals.actQueue = null;
298 }
299 }
300 if (ReactSharedInternals.thrownErrors.length > 0) {
301 const thrownError = aggregateErrors(ReactSharedInternals.thrownErrors);
302 ReactSharedInternals.thrownErrors.length = 0;
303 reject(thrownError);
304 } else {
305 resolve(returnValue);
306 }
307 }
308}
309
310let isFlushing = false;
311function flushActQueue(queue: Array<RendererTask>) {

Callers 1

thenFunction · 0.85

Calls 5

flushActQueueFunction · 0.85
aggregateErrorsFunction · 0.70
pushMethod · 0.65
rejectFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected