( returnValue: T, resolve: T => mixed, reject: mixed => mixed, )
| 269 | } |
| 270 | |
| 271 | function recursivelyFlushAsyncActWork<T>( |
| 272 | returnValue: T, |
| 273 | resolve: T => mixed, |
| 274 | reject: mixed => mixed, |
| 275 | ) { |
| 276 | if (__DEV__) { |
| 277 | class="cm">// Check if any tasks were scheduled asynchronously. |
| 278 | const queue = ReactSharedInternals.actQueue; |
| 279 | if (queue !== null) { |
| 280 | if (queue.length !== 0) { |
| 281 | class="cm">// Async tasks were scheduled, mostly likely in a microtask. |
| 282 | class="cm">// Keep flushing until there are no more. |
| 283 | try { |
| 284 | flushActQueue(queue); |
| 285 | class="cm">// The work we just performed may have schedule additional async |
| 286 | class="cm">// tasks. Wait a macrotask and check again. |
| 287 | queueMacrotask(() => |
| 288 | recursivelyFlushAsyncActWork(returnValue, resolve, reject), |
| 289 | ); |
| 290 | return; |
| 291 | } catch (error) { |
| 292 | class="cm">// Leave remaining tasks on the queue if something throws. |
| 293 | ReactSharedInternals.thrownErrors.push(error); |
| 294 | } |
| 295 | } else { |
| 296 | class="cm">// 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 | |
| 310 | let isFlushing = false; |
| 311 | function flushActQueue(queue: Array<RendererTask>) { |
no test coverage detected