MCPcopy Create free account
hub / github.com/microsoft/SandDance / unstable_wrap

Function unstable_wrap

docs/external/js/react.development.js:2988–3072  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

2986 return returnValue;
2987 }
2988 function unstable_wrap(callback) {
2989 var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID;
2990
2991 var wrappedInteractions = interactionsRef.current;
2992 var subscriber = subscriberRef.current;
2993
2994 if (subscriber !== null) {
2995 subscriber.onWorkScheduled(wrappedInteractions, threadID);
2996 } // Update the pending async work count for the current interactions.
2997 // Update after calling subscribers in case of error.
2998
2999
3000 wrappedInteractions.forEach(function (interaction) {
3001 interaction.__count++;
3002 });
3003 var hasRun = false;
3004
3005 function wrapped() {
3006 var prevInteractions = interactionsRef.current;
3007 interactionsRef.current = wrappedInteractions;
3008 subscriber = subscriberRef.current;
3009
3010 try {
3011 var returnValue;
3012
3013 try {
3014 if (subscriber !== null) {
3015 subscriber.onWorkStarted(wrappedInteractions, threadID);
3016 }
3017 } finally {
3018 try {
3019 returnValue = callback.apply(undefined, arguments);
3020 } finally {
3021 interactionsRef.current = prevInteractions;
3022
3023 if (subscriber !== null) {
3024 subscriber.onWorkStopped(wrappedInteractions, threadID);
3025 }
3026 }
3027 }
3028
3029 return returnValue;
3030 } finally {
3031 if (!hasRun) {
3032 // We only expect a wrapped function to be executed once,
3033 // But in the event that it's executed more than once–
3034 // Only decrement the outstanding interaction counts once.
3035 hasRun = true; // Update pending async counts for all wrapped interactions.
3036 // If this was the last scheduled async work for any of them,
3037 // Mark them as completed.
3038
3039 wrappedInteractions.forEach(function (interaction) {
3040 interaction.__count--;
3041
3042 if (subscriber !== null && interaction.__count === 0) {
3043 subscriber.onInteractionScheduledWorkCompleted(interaction);
3044 }
3045 });

Callers 1

Calls 1

forEachMethod · 0.45

Tested by

no test coverage detected