| 2934 | return ++threadIDCounter; |
| 2935 | } |
| 2936 | function unstable_trace(name, timestamp, callback) { |
| 2937 | var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID; |
| 2938 | |
| 2939 | var interaction = { |
| 2940 | __count: 1, |
| 2941 | id: interactionIDCounter++, |
| 2942 | name: name, |
| 2943 | timestamp: timestamp |
| 2944 | }; |
| 2945 | var prevInteractions = interactionsRef.current; // Traced interactions should stack/accumulate. |
| 2946 | // To do that, clone the current interactions. |
| 2947 | // The previous set will be restored upon completion. |
| 2948 | |
| 2949 | var interactions = new Set(prevInteractions); |
| 2950 | interactions.add(interaction); |
| 2951 | interactionsRef.current = interactions; |
| 2952 | var subscriber = subscriberRef.current; |
| 2953 | var returnValue; |
| 2954 | |
| 2955 | try { |
| 2956 | if (subscriber !== null) { |
| 2957 | subscriber.onInteractionTraced(interaction); |
| 2958 | } |
| 2959 | } finally { |
| 2960 | try { |
| 2961 | if (subscriber !== null) { |
| 2962 | subscriber.onWorkStarted(interactions, threadID); |
| 2963 | } |
| 2964 | } finally { |
| 2965 | try { |
| 2966 | returnValue = callback(); |
| 2967 | } finally { |
| 2968 | interactionsRef.current = prevInteractions; |
| 2969 | |
| 2970 | try { |
| 2971 | if (subscriber !== null) { |
| 2972 | subscriber.onWorkStopped(interactions, threadID); |
| 2973 | } |
| 2974 | } finally { |
| 2975 | interaction.__count--; // If no async work was scheduled for this interaction, |
| 2976 | // Notify subscribers that it's completed. |
| 2977 | |
| 2978 | if (subscriber !== null && interaction.__count === 0) { |
| 2979 | subscriber.onInteractionScheduledWorkCompleted(interaction); |
| 2980 | } |
| 2981 | } |
| 2982 | } |
| 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | return returnValue; |
| 2987 | } |
| 2988 | function unstable_wrap(callback) { |
| 2989 | var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID; |
| 2990 | |