MCPcopy Create free account
hub / github.com/react/react / entangleAsyncAction

Function entangleAsyncAction

packages/react-reconciler/src/ReactFiberAsyncAction.js:71–101  ·  view source on GitHub ↗
(
  transition: Transition,
  thenable: Thenable<S>,
)

Source from the content-addressed store, hash-verified

69let needsIsomorphicIndicator: boolean = false;
70
71export function entangleAsyncAction<S>(
72 transition: Transition,
73 thenable: Thenable<S>,
74): Thenable<S> {
75 // `thenable` is the return value of the async action scope function. Create
76 // a combined thenable that resolves once every entangled scope function
77 // has finished.
78 if (currentEntangledListeners === null) {
79 // There's no outer async action scope. Create a new one.
80 const entangledListeners = (currentEntangledListeners = []);
81 currentEntangledPendingCount = 0;
82 currentEntangledLane = requestTransitionLane(transition);
83 const entangledThenable: Thenable<void> = {
84 status: 'pending',
85 value: undefined,
86 then(resolve: void => mixed) {
87 entangledListeners.push(resolve);
88 },
89 };
90 currentEntangledActionThenable = entangledThenable;
91 if (enableDefaultTransitionIndicator) {
92 needsIsomorphicIndicator = true;
93 // We'll check if we need a default indicator in a microtask. Ensure
94 // we have this scheduled even if no root is scheduled.
95 ensureScheduleIsScheduled();
96 }
97 }
98 currentEntangledPendingCount++;
99 thenable.then(pingEngtangledActionScope, pingEngtangledActionScope);
100 return thenable;
101}
102
103function pingEngtangledActionScope() {
104 if (--currentEntangledPendingCount === 0) {

Callers 1

Calls 3

requestTransitionLaneFunction · 0.90
thenMethod · 0.65

Tested by

no test coverage detected