scheduler
Advanced tools
Comparing version 0.0.0-experimental-613e6f5fc-20230616 to 0.0.0-experimental-6230622a1a-20240610
@@ -36,4 +36,3 @@ /** | ||
var deadline = 0; | ||
var currentPriorityLevel_DEPRECATED = NormalPriority; // `isInputPending` is not available. Since we have no way of knowing if | ||
// there's pending input, always yield at the end of the frame. | ||
var currentPriorityLevel_DEPRECATED = NormalPriority; // Always yield at the end of the frame. | ||
@@ -68,5 +67,6 @@ function unstable_shouldYield() { | ||
var controller = new TaskController(); | ||
var controller = new TaskController({ | ||
priority: postTaskPriority | ||
}); | ||
var postTaskOptions = { | ||
priority: postTaskPriority, | ||
delay: typeof options === 'object' && options !== null ? options.delay : 0, | ||
@@ -93,11 +93,12 @@ signal: controller.signal | ||
var continuation = result; | ||
var continuationController = new TaskController(); | ||
var continuationOptions = { | ||
priority: postTaskPriority, | ||
signal: continuationController.signal | ||
}; // Update the original callback node's controller, since even though we're | ||
// posting a new task, conceptually it's the same one. | ||
signal: node._controller.signal | ||
}; | ||
var nextTask = runTask.bind(null, priorityLevel, postTaskPriority, node, continuation); | ||
node._controller = continuationController; | ||
scheduler.postTask(runTask.bind(null, priorityLevel, postTaskPriority, node, continuation), continuationOptions).catch(handleAbortError); | ||
if (scheduler.yield !== undefined) { | ||
scheduler.yield(continuationOptions).then(nextTask).catch(handleAbortError); | ||
} else { | ||
scheduler.postTask(nextTask, continuationOptions).catch(handleAbortError); | ||
} | ||
} | ||
@@ -104,0 +105,0 @@ } catch (error) { |
@@ -15,6 +15,3 @@ /** | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
'use strict'; | ||
if ( | ||
@@ -27,5 +24,8 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
var enableSchedulerDebugging = false; | ||
var enableSchedulerDebugging = false; | ||
var enableProfiling = false; | ||
var frameYieldMs = 5; | ||
var userBlockingPriorityTimeout = 250; | ||
var normalPriorityTimeout = 5000; | ||
var lowPriorityTimeout = 10000; | ||
@@ -146,12 +146,4 @@ function push(heap, node) { | ||
var maxSigned31BitInt = 1073741823; // Times out immediately | ||
var maxSigned31BitInt = 1073741823; // Tasks are stored on a min heap | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out | ||
var USER_BLOCKING_PRIORITY_TIMEOUT = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; // Never times out | ||
var IDLE_PRIORITY_TIMEOUT = maxSigned31BitInt; // Tasks are stored on a min heap | ||
var taskQueue = []; | ||
@@ -172,6 +164,2 @@ var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. | ||
typeof navigator !== 'undefined' && // $FlowFixMe[prop-missing] | ||
navigator.scheduling !== undefined && // $FlowFixMe[incompatible-type] | ||
navigator.scheduling.isInputPending !== undefined ? navigator.scheduling.isInputPending.bind(navigator.scheduling) : null; | ||
function advanceTimers(currentTime) { | ||
@@ -206,3 +194,3 @@ // Check for tasks that are no longer delayed and add them to the queue. | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} else { | ||
@@ -218,3 +206,3 @@ var firstTimer = peek(timerQueue); | ||
function flushWork(hasTimeRemaining, initialTime) { | ||
function flushWork(initialTime) { | ||
@@ -236,3 +224,3 @@ | ||
// No catch in prod code path. | ||
return workLoop(hasTimeRemaining, initialTime); | ||
return workLoop(initialTime); | ||
} | ||
@@ -246,3 +234,3 @@ } finally { | ||
function workLoop(hasTimeRemaining, initialTime) { | ||
function workLoop(initialTime) { | ||
var currentTime = initialTime; | ||
@@ -253,3 +241,3 @@ advanceTimers(currentTime); | ||
while (currentTask !== null && !(enableSchedulerDebugging )) { | ||
if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) { | ||
if (currentTask.expirationTime > currentTime && shouldYieldToHost()) { | ||
// This currentTask hasn't expired, and we've reached the deadline. | ||
@@ -397,15 +385,19 @@ break; | ||
case ImmediatePriority: | ||
timeout = IMMEDIATE_PRIORITY_TIMEOUT; | ||
// Times out immediately | ||
timeout = -1; | ||
break; | ||
case UserBlockingPriority: | ||
timeout = USER_BLOCKING_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = userBlockingPriorityTimeout; | ||
break; | ||
case IdlePriority: | ||
timeout = IDLE_PRIORITY_TIMEOUT; | ||
// Never times out | ||
timeout = maxSigned31BitInt; | ||
break; | ||
case LowPriority: | ||
timeout = LOW_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = lowPriorityTimeout; | ||
break; | ||
@@ -415,3 +407,4 @@ | ||
default: | ||
timeout = NORMAL_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = normalPriorityTimeout; | ||
break; | ||
@@ -455,3 +448,3 @@ } | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} | ||
@@ -470,3 +463,3 @@ } | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} | ||
@@ -492,3 +485,2 @@ } | ||
var isMessageLoopRunning = false; | ||
var scheduledHostCallback = null; | ||
var taskTimeoutID = -1; // Scheduler periodically yields in case there is other work on the main | ||
@@ -509,3 +501,3 @@ // thread, like user events. By default, it yields multiple times per frame. | ||
return false; | ||
} // The main thread has been blocked for a non-negligible amount of time. We | ||
} // Yield now. | ||
@@ -516,6 +508,4 @@ | ||
function requestPaint() { | ||
function requestPaint() {} | ||
} | ||
function forceFrameRate(fps) { | ||
@@ -537,13 +527,12 @@ if (fps < 0 || fps > 125) { | ||
var performWorkUntilDeadline = function () { | ||
if (scheduledHostCallback !== null) { | ||
if (isMessageLoopRunning) { | ||
var currentTime = exports.unstable_now(); // Keep track of the start time so we can measure how long the main thread | ||
// has been blocked. | ||
startTime = currentTime; | ||
var hasTimeRemaining = true; // If a scheduler task throws, exit the current browser task so the | ||
startTime = currentTime; // If a scheduler task throws, exit the current browser task so the | ||
// error can be observed. | ||
// | ||
// Intentionally not using a try-catch, since that makes some debugging | ||
// techniques harder. Instead, if `scheduledHostCallback` errors, then | ||
// `hasMoreWork` will remain true, and we'll continue the work loop. | ||
// techniques harder. Instead, if `flushWork` errors, then `hasMoreWork` will | ||
// remain true, and we'll continue the work loop. | ||
@@ -553,4 +542,3 @@ var hasMoreWork = true; | ||
try { | ||
// $FlowFixMe[not-a-function] found when upgrading Flow | ||
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime); | ||
hasMoreWork = flushWork(currentTime); | ||
} finally { | ||
@@ -563,8 +551,5 @@ if (hasMoreWork) { | ||
isMessageLoopRunning = false; | ||
scheduledHostCallback = null; | ||
} | ||
} | ||
} else { | ||
isMessageLoopRunning = false; | ||
} // Yielding to the browser will give it a chance to paint, so we can | ||
} | ||
}; | ||
@@ -607,5 +592,3 @@ | ||
function requestHostCallback(callback) { | ||
scheduledHostCallback = callback; | ||
function requestHostCallback() { | ||
if (!isMessageLoopRunning) { | ||
@@ -649,3 +632,2 @@ isMessageLoopRunning = true; | ||
exports.unstable_wrapCallback = unstable_wrapCallback; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
@@ -658,4 +640,4 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
})(); | ||
} |
@@ -20,2 +20,5 @@ /** | ||
var frameYieldMs = 5; | ||
var userBlockingPriorityTimeout = 250; | ||
var normalPriorityTimeout = 5000; | ||
var lowPriorityTimeout = 10000; | ||
@@ -136,12 +139,4 @@ function push(heap, node) { | ||
var maxSigned31BitInt = 1073741823; // Times out immediately | ||
var maxSigned31BitInt = 1073741823; // Tasks are stored on a min heap | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out | ||
var USER_BLOCKING_PRIORITY_TIMEOUT = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; // Never times out | ||
var IDLE_PRIORITY_TIMEOUT = maxSigned31BitInt; // Tasks are stored on a min heap | ||
var taskQueue = []; | ||
@@ -162,6 +157,2 @@ var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. | ||
typeof navigator !== 'undefined' && // $FlowFixMe[prop-missing] | ||
navigator.scheduling !== undefined && // $FlowFixMe[incompatible-type] | ||
navigator.scheduling.isInputPending !== undefined ? navigator.scheduling.isInputPending.bind(navigator.scheduling) : null; | ||
function advanceTimers(currentTime) { | ||
@@ -196,3 +187,3 @@ // Check for tasks that are no longer delayed and add them to the queue. | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} else { | ||
@@ -208,3 +199,3 @@ var firstTimer = peek(timerQueue); | ||
function flushWork(hasTimeRemaining, initialTime) { | ||
function flushWork(initialTime) { | ||
@@ -226,3 +217,3 @@ | ||
// No catch in prod code path. | ||
return workLoop(hasTimeRemaining, initialTime); | ||
return workLoop(initialTime); | ||
} | ||
@@ -236,3 +227,3 @@ } finally { | ||
function workLoop(hasTimeRemaining, initialTime) { | ||
function workLoop(initialTime) { | ||
var currentTime = initialTime; | ||
@@ -243,3 +234,3 @@ advanceTimers(currentTime); | ||
while (currentTask !== null && !(enableSchedulerDebugging )) { | ||
if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) { | ||
if (currentTask.expirationTime > currentTime && shouldYieldToHost()) { | ||
// This currentTask hasn't expired, and we've reached the deadline. | ||
@@ -320,15 +311,19 @@ break; | ||
case ImmediatePriority: | ||
timeout = IMMEDIATE_PRIORITY_TIMEOUT; | ||
// Times out immediately | ||
timeout = -1; | ||
break; | ||
case UserBlockingPriority: | ||
timeout = USER_BLOCKING_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = userBlockingPriorityTimeout; | ||
break; | ||
case IdlePriority: | ||
timeout = IDLE_PRIORITY_TIMEOUT; | ||
// Never times out | ||
timeout = maxSigned31BitInt; | ||
break; | ||
case LowPriority: | ||
timeout = LOW_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = lowPriorityTimeout; | ||
break; | ||
@@ -338,3 +333,4 @@ | ||
default: | ||
timeout = NORMAL_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = normalPriorityTimeout; | ||
break; | ||
@@ -378,3 +374,3 @@ } | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} | ||
@@ -399,3 +395,2 @@ } | ||
var isMessageLoopRunning = false; | ||
var scheduledHostCallback = null; | ||
var taskTimeoutID = -1; // Scheduler periodically yields in case there is other work on the main | ||
@@ -416,3 +411,3 @@ // thread, like user events. By default, it yields multiple times per frame. | ||
return false; | ||
} // The main thread has been blocked for a non-negligible amount of time. We | ||
} // Yield now. | ||
@@ -423,18 +418,15 @@ | ||
function requestPaint() { | ||
function requestPaint() {} | ||
} | ||
var performWorkUntilDeadline = function () { | ||
if (scheduledHostCallback !== null) { | ||
if (isMessageLoopRunning) { | ||
var currentTime = getCurrentTime(); // Keep track of the start time so we can measure how long the main thread | ||
// has been blocked. | ||
startTime = currentTime; | ||
var hasTimeRemaining = true; // If a scheduler task throws, exit the current browser task so the | ||
startTime = currentTime; // If a scheduler task throws, exit the current browser task so the | ||
// error can be observed. | ||
// | ||
// Intentionally not using a try-catch, since that makes some debugging | ||
// techniques harder. Instead, if `scheduledHostCallback` errors, then | ||
// `hasMoreWork` will remain true, and we'll continue the work loop. | ||
// techniques harder. Instead, if `flushWork` errors, then `hasMoreWork` will | ||
// remain true, and we'll continue the work loop. | ||
@@ -444,4 +436,3 @@ var hasMoreWork = true; | ||
try { | ||
// $FlowFixMe[not-a-function] found when upgrading Flow | ||
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime); | ||
hasMoreWork = flushWork(currentTime); | ||
} finally { | ||
@@ -454,8 +445,5 @@ if (hasMoreWork) { | ||
isMessageLoopRunning = false; | ||
scheduledHostCallback = null; | ||
} | ||
} | ||
} else { | ||
isMessageLoopRunning = false; | ||
} // Yielding to the browser will give it a chance to paint, so we can | ||
} | ||
}; | ||
@@ -498,5 +486,3 @@ | ||
function requestHostCallback(callback) { | ||
scheduledHostCallback = callback; | ||
function requestHostCallback() { | ||
if (!isMessageLoopRunning) { | ||
@@ -503,0 +489,0 @@ isMessageLoopRunning = true; |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/scheduler.production.min.js'); | ||
module.exports = require('./cjs/scheduler.production.js'); | ||
} else { | ||
module.exports = require('./cjs/scheduler.development.js'); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/scheduler.native.production.min.js'); | ||
module.exports = require('./cjs/scheduler.native.production.js'); | ||
} else { | ||
module.exports = require('./cjs/scheduler.native.development.js'); | ||
} |
{ | ||
"name": "scheduler", | ||
"version": "0.0.0-experimental-613e6f5fc-20230616", | ||
"version": "0.0.0-experimental-6230622a1a-20240610", | ||
"description": "Cooperative scheduler for the browser environment.", | ||
@@ -17,6 +17,3 @@ "repository": { | ||
}, | ||
"homepage": "https://reactjs.org/", | ||
"dependencies": { | ||
"loose-envify": "^1.1.0" | ||
}, | ||
"homepage": "https://react.dev/", | ||
"files": [ | ||
@@ -29,10 +26,4 @@ "LICENSE", | ||
"unstable_post_task.js", | ||
"cjs/", | ||
"umd/" | ||
], | ||
"browserify": { | ||
"transform": [ | ||
"loose-envify" | ||
] | ||
} | ||
"cjs/" | ||
] | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/scheduler-unstable_mock.production.min.js'); | ||
module.exports = require('./cjs/scheduler-unstable_mock.production.js'); | ||
} else { | ||
module.exports = require('./cjs/scheduler-unstable_mock.development.js'); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/scheduler-unstable_post_task.production.min.js'); | ||
module.exports = require('./cjs/scheduler-unstable_post_task.production.js'); | ||
} else { | ||
module.exports = require('./cjs/scheduler-unstable_post_task.development.js'); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
2950
99114
15
- Removedloose-envify@^1.1.0
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)