1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 |
|
13 |
|
14 | if (process.env.NODE_ENV !== "production") {
|
15 | (function() {
|
16 | 'use strict';
|
17 |
|
18 | Object.defineProperty(exports, '__esModule', { value: true });
|
19 |
|
20 | var enableSchedulerDebugging = false;
|
21 |
|
22 |
|
23 | var enableProfiling = true;
|
24 |
|
25 | var currentTime = 0;
|
26 | var scheduledCallback = null;
|
27 | var scheduledTimeout = null;
|
28 | var timeoutTime = -1;
|
29 | var yieldedValues = null;
|
30 | var expectedNumberOfYields = -1;
|
31 | var didStop = false;
|
32 | var isFlushing = false;
|
33 | var needsPaint = false;
|
34 | var shouldYieldForPaint = false;
|
35 | function requestHostCallback(callback) {
|
36 | scheduledCallback = callback;
|
37 | }
|
38 |
|
39 | function requestHostTimeout(callback, ms) {
|
40 | scheduledTimeout = callback;
|
41 | timeoutTime = currentTime + ms;
|
42 | }
|
43 | function cancelHostTimeout() {
|
44 | scheduledTimeout = null;
|
45 | timeoutTime = -1;
|
46 | }
|
47 | function shouldYieldToHost() {
|
48 | if (expectedNumberOfYields !== -1 && yieldedValues !== null && yieldedValues.length >= expectedNumberOfYields || shouldYieldForPaint && needsPaint) {
|
49 |
|
50 | didStop = true;
|
51 | return true;
|
52 | }
|
53 |
|
54 | return false;
|
55 | }
|
56 | function getCurrentTime() {
|
57 | return currentTime;
|
58 | }
|
59 | function forceFrameRate() {
|
60 | }
|
61 |
|
62 |
|
63 | function unstable_flushNumberOfYields(count) {
|
64 | if (isFlushing) {
|
65 | throw new Error('Already flushing work.');
|
66 | }
|
67 |
|
68 | if (scheduledCallback !== null) {
|
69 | var cb = scheduledCallback;
|
70 | expectedNumberOfYields = count;
|
71 | isFlushing = true;
|
72 |
|
73 | try {
|
74 | var hasMoreWork = true;
|
75 |
|
76 | do {
|
77 | hasMoreWork = cb(true, currentTime);
|
78 | } while (hasMoreWork && !didStop);
|
79 |
|
80 | if (!hasMoreWork) {
|
81 | scheduledCallback = null;
|
82 | }
|
83 | } finally {
|
84 | expectedNumberOfYields = -1;
|
85 | didStop = false;
|
86 | isFlushing = false;
|
87 | }
|
88 | }
|
89 | }
|
90 | function unstable_flushUntilNextPaint() {
|
91 | if (isFlushing) {
|
92 | throw new Error('Already flushing work.');
|
93 | }
|
94 |
|
95 | if (scheduledCallback !== null) {
|
96 | var cb = scheduledCallback;
|
97 | shouldYieldForPaint = true;
|
98 | needsPaint = false;
|
99 | isFlushing = true;
|
100 |
|
101 | try {
|
102 | var hasMoreWork = true;
|
103 |
|
104 | do {
|
105 | hasMoreWork = cb(true, currentTime);
|
106 | } while (hasMoreWork && !didStop);
|
107 |
|
108 | if (!hasMoreWork) {
|
109 | scheduledCallback = null;
|
110 | }
|
111 | } finally {
|
112 | shouldYieldForPaint = false;
|
113 | didStop = false;
|
114 | isFlushing = false;
|
115 | }
|
116 | }
|
117 | }
|
118 | function unstable_flushExpired() {
|
119 | if (isFlushing) {
|
120 | throw new Error('Already flushing work.');
|
121 | }
|
122 |
|
123 | if (scheduledCallback !== null) {
|
124 | isFlushing = true;
|
125 |
|
126 | try {
|
127 | var hasMoreWork = scheduledCallback(false, currentTime);
|
128 |
|
129 | if (!hasMoreWork) {
|
130 | scheduledCallback = null;
|
131 | }
|
132 | } finally {
|
133 | isFlushing = false;
|
134 | }
|
135 | }
|
136 | }
|
137 | function unstable_flushAllWithoutAsserting() {
|
138 |
|
139 | if (isFlushing) {
|
140 | throw new Error('Already flushing work.');
|
141 | }
|
142 |
|
143 | if (scheduledCallback !== null) {
|
144 | var cb = scheduledCallback;
|
145 | isFlushing = true;
|
146 |
|
147 | try {
|
148 | var hasMoreWork = true;
|
149 |
|
150 | do {
|
151 | hasMoreWork = cb(true, currentTime);
|
152 | } while (hasMoreWork);
|
153 |
|
154 | if (!hasMoreWork) {
|
155 | scheduledCallback = null;
|
156 | }
|
157 |
|
158 | return true;
|
159 | } finally {
|
160 | isFlushing = false;
|
161 | }
|
162 | } else {
|
163 | return false;
|
164 | }
|
165 | }
|
166 | function unstable_clearYields() {
|
167 | if (yieldedValues === null) {
|
168 | return [];
|
169 | }
|
170 |
|
171 | var values = yieldedValues;
|
172 | yieldedValues = null;
|
173 | return values;
|
174 | }
|
175 | function unstable_flushAll() {
|
176 | if (yieldedValues !== null) {
|
177 | throw new Error('Log is not empty. Assert on the log of yielded values before ' + 'flushing additional work.');
|
178 | }
|
179 |
|
180 | unstable_flushAllWithoutAsserting();
|
181 |
|
182 | if (yieldedValues !== null) {
|
183 | throw new Error('While flushing work, something yielded a value. Use an ' + 'assertion helper to assert on the log of yielded values, e.g. ' + 'expect(Scheduler).toFlushAndYield([...])');
|
184 | }
|
185 | }
|
186 | function unstable_yieldValue(value) {
|
187 | if (yieldedValues === null) {
|
188 | yieldedValues = [value];
|
189 | } else {
|
190 | yieldedValues.push(value);
|
191 | }
|
192 | }
|
193 | function unstable_advanceTime(ms) {
|
194 | currentTime += ms;
|
195 |
|
196 | if (!isFlushing) {
|
197 | if (scheduledTimeout !== null && timeoutTime <= currentTime) {
|
198 | scheduledTimeout(currentTime);
|
199 | timeoutTime = -1;
|
200 | scheduledTimeout = null;
|
201 | }
|
202 |
|
203 | unstable_flushExpired();
|
204 | }
|
205 | }
|
206 | function requestPaint() {
|
207 | needsPaint = true;
|
208 | }
|
209 |
|
210 | function push(heap, node) {
|
211 | var index = heap.length;
|
212 | heap.push(node);
|
213 | siftUp(heap, node, index);
|
214 | }
|
215 | function peek(heap) {
|
216 | var first = heap[0];
|
217 | return first === undefined ? null : first;
|
218 | }
|
219 | function pop(heap) {
|
220 | var first = heap[0];
|
221 |
|
222 | if (first !== undefined) {
|
223 | var last = heap.pop();
|
224 |
|
225 | if (last !== first) {
|
226 | heap[0] = last;
|
227 | siftDown(heap, last, 0);
|
228 | }
|
229 |
|
230 | return first;
|
231 | } else {
|
232 | return null;
|
233 | }
|
234 | }
|
235 |
|
236 | function siftUp(heap, node, i) {
|
237 | var index = i;
|
238 |
|
239 | while (true) {
|
240 | var parentIndex = Math.floor((index - 1) / 2);
|
241 | var parent = heap[parentIndex];
|
242 |
|
243 | if (parent !== undefined && compare(parent, node) > 0) {
|
244 |
|
245 | heap[parentIndex] = node;
|
246 | heap[index] = parent;
|
247 | index = parentIndex;
|
248 | } else {
|
249 |
|
250 | return;
|
251 | }
|
252 | }
|
253 | }
|
254 |
|
255 | function siftDown(heap, node, i) {
|
256 | var index = i;
|
257 | var length = heap.length;
|
258 |
|
259 | while (index < length) {
|
260 | var leftIndex = (index + 1) * 2 - 1;
|
261 | var left = heap[leftIndex];
|
262 | var rightIndex = leftIndex + 1;
|
263 | var right = heap[rightIndex];
|
264 |
|
265 | if (left !== undefined && compare(left, node) < 0) {
|
266 | if (right !== undefined && compare(right, left) < 0) {
|
267 | heap[index] = right;
|
268 | heap[rightIndex] = node;
|
269 | index = rightIndex;
|
270 | } else {
|
271 | heap[index] = left;
|
272 | heap[leftIndex] = node;
|
273 | index = leftIndex;
|
274 | }
|
275 | } else if (right !== undefined && compare(right, node) < 0) {
|
276 | heap[index] = right;
|
277 | heap[rightIndex] = node;
|
278 | index = rightIndex;
|
279 | } else {
|
280 |
|
281 | return;
|
282 | }
|
283 | }
|
284 | }
|
285 |
|
286 | function compare(a, b) {
|
287 |
|
288 | var diff = a.sortIndex - b.sortIndex;
|
289 | return diff !== 0 ? diff : a.id - b.id;
|
290 | }
|
291 |
|
292 |
|
293 | var NoPriority = 0;
|
294 | var ImmediatePriority = 1;
|
295 | var UserBlockingPriority = 2;
|
296 | var NormalPriority = 3;
|
297 | var LowPriority = 4;
|
298 | var IdlePriority = 5;
|
299 |
|
300 | var runIdCounter = 0;
|
301 | var mainThreadIdCounter = 0;
|
302 | var profilingStateSize = 4;
|
303 | var sharedProfilingBuffer = enableProfiling ?
|
304 | typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) :
|
305 | typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null
|
306 | : null;
|
307 | var profilingState = enableProfiling && sharedProfilingBuffer !== null ? new Int32Array(sharedProfilingBuffer) : [];
|
308 |
|
309 | var PRIORITY = 0;
|
310 | var CURRENT_TASK_ID = 1;
|
311 | var CURRENT_RUN_ID = 2;
|
312 | var QUEUE_SIZE = 3;
|
313 |
|
314 | if (enableProfiling) {
|
315 | profilingState[PRIORITY] = NoPriority;
|
316 |
|
317 |
|
318 | profilingState[QUEUE_SIZE] = 0;
|
319 | profilingState[CURRENT_TASK_ID] = 0;
|
320 | }
|
321 |
|
322 |
|
323 | var INITIAL_EVENT_LOG_SIZE = 131072;
|
324 | var MAX_EVENT_LOG_SIZE = 524288;
|
325 |
|
326 | var eventLogSize = 0;
|
327 | var eventLogBuffer = null;
|
328 | var eventLog = null;
|
329 | var eventLogIndex = 0;
|
330 | var TaskStartEvent = 1;
|
331 | var TaskCompleteEvent = 2;
|
332 | var TaskErrorEvent = 3;
|
333 | var TaskCancelEvent = 4;
|
334 | var TaskRunEvent = 5;
|
335 | var TaskYieldEvent = 6;
|
336 | var SchedulerSuspendEvent = 7;
|
337 | var SchedulerResumeEvent = 8;
|
338 |
|
339 | function logEvent(entries) {
|
340 | if (eventLog !== null) {
|
341 | var offset = eventLogIndex;
|
342 | eventLogIndex += entries.length;
|
343 |
|
344 | if (eventLogIndex + 1 > eventLogSize) {
|
345 | eventLogSize *= 2;
|
346 |
|
347 | if (eventLogSize > MAX_EVENT_LOG_SIZE) {
|
348 | console.error("Scheduler Profiling: Event log exceeded maximum size. Don't " + 'forget to call `stopLoggingProfilingEvents()`.');
|
349 | stopLoggingProfilingEvents();
|
350 | return;
|
351 | }
|
352 |
|
353 | var newEventLog = new Int32Array(eventLogSize * 4);
|
354 | newEventLog.set(eventLog);
|
355 | eventLogBuffer = newEventLog.buffer;
|
356 | eventLog = newEventLog;
|
357 | }
|
358 |
|
359 | eventLog.set(entries, offset);
|
360 | }
|
361 | }
|
362 |
|
363 | function startLoggingProfilingEvents() {
|
364 | eventLogSize = INITIAL_EVENT_LOG_SIZE;
|
365 | eventLogBuffer = new ArrayBuffer(eventLogSize * 4);
|
366 | eventLog = new Int32Array(eventLogBuffer);
|
367 | eventLogIndex = 0;
|
368 | }
|
369 | function stopLoggingProfilingEvents() {
|
370 | var buffer = eventLogBuffer;
|
371 | eventLogSize = 0;
|
372 | eventLogBuffer = null;
|
373 | eventLog = null;
|
374 | eventLogIndex = 0;
|
375 | return buffer;
|
376 | }
|
377 | function markTaskStart(task, ms) {
|
378 | if (enableProfiling) {
|
379 | profilingState[QUEUE_SIZE]++;
|
380 |
|
381 | if (eventLog !== null) {
|
382 |
|
383 |
|
384 |
|
385 | logEvent([TaskStartEvent, ms * 1000, task.id, task.priorityLevel]);
|
386 | }
|
387 | }
|
388 | }
|
389 | function markTaskCompleted(task, ms) {
|
390 | if (enableProfiling) {
|
391 | profilingState[PRIORITY] = NoPriority;
|
392 | profilingState[CURRENT_TASK_ID] = 0;
|
393 | profilingState[QUEUE_SIZE]--;
|
394 |
|
395 | if (eventLog !== null) {
|
396 | logEvent([TaskCompleteEvent, ms * 1000, task.id]);
|
397 | }
|
398 | }
|
399 | }
|
400 | function markTaskCanceled(task, ms) {
|
401 | if (enableProfiling) {
|
402 | profilingState[QUEUE_SIZE]--;
|
403 |
|
404 | if (eventLog !== null) {
|
405 | logEvent([TaskCancelEvent, ms * 1000, task.id]);
|
406 | }
|
407 | }
|
408 | }
|
409 | function markTaskErrored(task, ms) {
|
410 | if (enableProfiling) {
|
411 | profilingState[PRIORITY] = NoPriority;
|
412 | profilingState[CURRENT_TASK_ID] = 0;
|
413 | profilingState[QUEUE_SIZE]--;
|
414 |
|
415 | if (eventLog !== null) {
|
416 | logEvent([TaskErrorEvent, ms * 1000, task.id]);
|
417 | }
|
418 | }
|
419 | }
|
420 | function markTaskRun(task, ms) {
|
421 | if (enableProfiling) {
|
422 | runIdCounter++;
|
423 | profilingState[PRIORITY] = task.priorityLevel;
|
424 | profilingState[CURRENT_TASK_ID] = task.id;
|
425 | profilingState[CURRENT_RUN_ID] = runIdCounter;
|
426 |
|
427 | if (eventLog !== null) {
|
428 | logEvent([TaskRunEvent, ms * 1000, task.id, runIdCounter]);
|
429 | }
|
430 | }
|
431 | }
|
432 | function markTaskYield(task, ms) {
|
433 | if (enableProfiling) {
|
434 | profilingState[PRIORITY] = NoPriority;
|
435 | profilingState[CURRENT_TASK_ID] = 0;
|
436 | profilingState[CURRENT_RUN_ID] = 0;
|
437 |
|
438 | if (eventLog !== null) {
|
439 | logEvent([TaskYieldEvent, ms * 1000, task.id, runIdCounter]);
|
440 | }
|
441 | }
|
442 | }
|
443 | function markSchedulerSuspended(ms) {
|
444 | if (enableProfiling) {
|
445 | mainThreadIdCounter++;
|
446 |
|
447 | if (eventLog !== null) {
|
448 | logEvent([SchedulerSuspendEvent, ms * 1000, mainThreadIdCounter]);
|
449 | }
|
450 | }
|
451 | }
|
452 | function markSchedulerUnsuspended(ms) {
|
453 | if (enableProfiling) {
|
454 | if (eventLog !== null) {
|
455 | logEvent([SchedulerResumeEvent, ms * 1000, mainThreadIdCounter]);
|
456 | }
|
457 | }
|
458 | }
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 | var maxSigned31BitInt = 1073741823;
|
465 |
|
466 | var IMMEDIATE_PRIORITY_TIMEOUT = -1;
|
467 |
|
468 | var USER_BLOCKING_PRIORITY = 250;
|
469 | var NORMAL_PRIORITY_TIMEOUT = 5000;
|
470 | var LOW_PRIORITY_TIMEOUT = 10000;
|
471 |
|
472 | var IDLE_PRIORITY = maxSigned31BitInt;
|
473 |
|
474 | var taskQueue = [];
|
475 | var timerQueue = [];
|
476 |
|
477 | var taskIdCounter = 1;
|
478 |
|
479 | var isSchedulerPaused = false;
|
480 | var currentTask = null;
|
481 | var currentPriorityLevel = NormalPriority;
|
482 |
|
483 | var isPerformingWork = false;
|
484 | var isHostCallbackScheduled = false;
|
485 | var isHostTimeoutScheduled = false;
|
486 |
|
487 | function advanceTimers(currentTime) {
|
488 |
|
489 | var timer = peek(timerQueue);
|
490 |
|
491 | while (timer !== null) {
|
492 | if (timer.callback === null) {
|
493 |
|
494 | pop(timerQueue);
|
495 | } else if (timer.startTime <= currentTime) {
|
496 |
|
497 | pop(timerQueue);
|
498 | timer.sortIndex = timer.expirationTime;
|
499 | push(taskQueue, timer);
|
500 |
|
501 | if (enableProfiling) {
|
502 | markTaskStart(timer, currentTime);
|
503 | timer.isQueued = true;
|
504 | }
|
505 | } else {
|
506 |
|
507 | return;
|
508 | }
|
509 |
|
510 | timer = peek(timerQueue);
|
511 | }
|
512 | }
|
513 |
|
514 | function handleTimeout(currentTime) {
|
515 | isHostTimeoutScheduled = false;
|
516 | advanceTimers(currentTime);
|
517 |
|
518 | if (!isHostCallbackScheduled) {
|
519 | if (peek(taskQueue) !== null) {
|
520 | isHostCallbackScheduled = true;
|
521 | requestHostCallback(flushWork);
|
522 | } else {
|
523 | var firstTimer = peek(timerQueue);
|
524 |
|
525 | if (firstTimer !== null) {
|
526 | requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime);
|
527 | }
|
528 | }
|
529 | }
|
530 | }
|
531 |
|
532 | function flushWork(hasTimeRemaining, initialTime) {
|
533 | if (enableProfiling) {
|
534 | markSchedulerUnsuspended(initialTime);
|
535 | }
|
536 |
|
537 |
|
538 | isHostCallbackScheduled = false;
|
539 |
|
540 | if (isHostTimeoutScheduled) {
|
541 |
|
542 | isHostTimeoutScheduled = false;
|
543 | cancelHostTimeout();
|
544 | }
|
545 |
|
546 | isPerformingWork = true;
|
547 | var previousPriorityLevel = currentPriorityLevel;
|
548 |
|
549 | try {
|
550 | if (enableProfiling) {
|
551 | try {
|
552 | return workLoop(hasTimeRemaining, initialTime);
|
553 | } catch (error) {
|
554 | if (currentTask !== null) {
|
555 | var currentTime = getCurrentTime();
|
556 | markTaskErrored(currentTask, currentTime);
|
557 | currentTask.isQueued = false;
|
558 | }
|
559 |
|
560 | throw error;
|
561 | }
|
562 | } else {
|
563 |
|
564 | return workLoop(hasTimeRemaining, initialTime);
|
565 | }
|
566 | } finally {
|
567 | currentTask = null;
|
568 | currentPriorityLevel = previousPriorityLevel;
|
569 | isPerformingWork = false;
|
570 |
|
571 | if (enableProfiling) {
|
572 | var _currentTime = getCurrentTime();
|
573 |
|
574 | markSchedulerSuspended(_currentTime);
|
575 | }
|
576 | }
|
577 | }
|
578 |
|
579 | function workLoop(hasTimeRemaining, initialTime) {
|
580 | var currentTime = initialTime;
|
581 | advanceTimers(currentTime);
|
582 | currentTask = peek(taskQueue);
|
583 |
|
584 | while (currentTask !== null && !(enableSchedulerDebugging && isSchedulerPaused)) {
|
585 | if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) {
|
586 |
|
587 | break;
|
588 | }
|
589 |
|
590 | var callback = currentTask.callback;
|
591 |
|
592 | if (callback !== null) {
|
593 | currentTask.callback = null;
|
594 | currentPriorityLevel = currentTask.priorityLevel;
|
595 | var didUserCallbackTimeout = currentTask.expirationTime <= currentTime;
|
596 | markTaskRun(currentTask, currentTime);
|
597 | var continuationCallback = callback(didUserCallbackTimeout);
|
598 | currentTime = getCurrentTime();
|
599 |
|
600 | if (typeof continuationCallback === 'function') {
|
601 | currentTask.callback = continuationCallback;
|
602 | markTaskYield(currentTask, currentTime);
|
603 | } else {
|
604 | if (enableProfiling) {
|
605 | markTaskCompleted(currentTask, currentTime);
|
606 | currentTask.isQueued = false;
|
607 | }
|
608 |
|
609 | if (currentTask === peek(taskQueue)) {
|
610 | pop(taskQueue);
|
611 | }
|
612 | }
|
613 |
|
614 | advanceTimers(currentTime);
|
615 | } else {
|
616 | pop(taskQueue);
|
617 | }
|
618 |
|
619 | currentTask = peek(taskQueue);
|
620 | }
|
621 |
|
622 |
|
623 | if (currentTask !== null) {
|
624 | return true;
|
625 | } else {
|
626 | var firstTimer = peek(timerQueue);
|
627 |
|
628 | if (firstTimer !== null) {
|
629 | requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime);
|
630 | }
|
631 |
|
632 | return false;
|
633 | }
|
634 | }
|
635 |
|
636 | function unstable_runWithPriority(priorityLevel, eventHandler) {
|
637 | switch (priorityLevel) {
|
638 | case ImmediatePriority:
|
639 | case UserBlockingPriority:
|
640 | case NormalPriority:
|
641 | case LowPriority:
|
642 | case IdlePriority:
|
643 | break;
|
644 |
|
645 | default:
|
646 | priorityLevel = NormalPriority;
|
647 | }
|
648 |
|
649 | var previousPriorityLevel = currentPriorityLevel;
|
650 | currentPriorityLevel = priorityLevel;
|
651 |
|
652 | try {
|
653 | return eventHandler();
|
654 | } finally {
|
655 | currentPriorityLevel = previousPriorityLevel;
|
656 | }
|
657 | }
|
658 |
|
659 | function unstable_next(eventHandler) {
|
660 | var priorityLevel;
|
661 |
|
662 | switch (currentPriorityLevel) {
|
663 | case ImmediatePriority:
|
664 | case UserBlockingPriority:
|
665 | case NormalPriority:
|
666 |
|
667 | priorityLevel = NormalPriority;
|
668 | break;
|
669 |
|
670 | default:
|
671 |
|
672 | priorityLevel = currentPriorityLevel;
|
673 | break;
|
674 | }
|
675 |
|
676 | var previousPriorityLevel = currentPriorityLevel;
|
677 | currentPriorityLevel = priorityLevel;
|
678 |
|
679 | try {
|
680 | return eventHandler();
|
681 | } finally {
|
682 | currentPriorityLevel = previousPriorityLevel;
|
683 | }
|
684 | }
|
685 |
|
686 | function unstable_wrapCallback(callback) {
|
687 | var parentPriorityLevel = currentPriorityLevel;
|
688 | return function () {
|
689 |
|
690 | var previousPriorityLevel = currentPriorityLevel;
|
691 | currentPriorityLevel = parentPriorityLevel;
|
692 |
|
693 | try {
|
694 | return callback.apply(this, arguments);
|
695 | } finally {
|
696 | currentPriorityLevel = previousPriorityLevel;
|
697 | }
|
698 | };
|
699 | }
|
700 |
|
701 | function timeoutForPriorityLevel(priorityLevel) {
|
702 | switch (priorityLevel) {
|
703 | case ImmediatePriority:
|
704 | return IMMEDIATE_PRIORITY_TIMEOUT;
|
705 |
|
706 | case UserBlockingPriority:
|
707 | return USER_BLOCKING_PRIORITY;
|
708 |
|
709 | case IdlePriority:
|
710 | return IDLE_PRIORITY;
|
711 |
|
712 | case LowPriority:
|
713 | return LOW_PRIORITY_TIMEOUT;
|
714 |
|
715 | case NormalPriority:
|
716 | default:
|
717 | return NORMAL_PRIORITY_TIMEOUT;
|
718 | }
|
719 | }
|
720 |
|
721 | function unstable_scheduleCallback(priorityLevel, callback, options) {
|
722 | var currentTime = getCurrentTime();
|
723 | var startTime;
|
724 | var timeout;
|
725 |
|
726 | if (typeof options === 'object' && options !== null) {
|
727 | var delay = options.delay;
|
728 |
|
729 | if (typeof delay === 'number' && delay > 0) {
|
730 | startTime = currentTime + delay;
|
731 | } else {
|
732 | startTime = currentTime;
|
733 | }
|
734 |
|
735 | timeout = typeof options.timeout === 'number' ? options.timeout : timeoutForPriorityLevel(priorityLevel);
|
736 | } else {
|
737 | timeout = timeoutForPriorityLevel(priorityLevel);
|
738 | startTime = currentTime;
|
739 | }
|
740 |
|
741 | var expirationTime = startTime + timeout;
|
742 | var newTask = {
|
743 | id: taskIdCounter++,
|
744 | callback: callback,
|
745 | priorityLevel: priorityLevel,
|
746 | startTime: startTime,
|
747 | expirationTime: expirationTime,
|
748 | sortIndex: -1
|
749 | };
|
750 |
|
751 | if (enableProfiling) {
|
752 | newTask.isQueued = false;
|
753 | }
|
754 |
|
755 | if (startTime > currentTime) {
|
756 |
|
757 | newTask.sortIndex = startTime;
|
758 | push(timerQueue, newTask);
|
759 |
|
760 | if (peek(taskQueue) === null && newTask === peek(timerQueue)) {
|
761 |
|
762 | if (isHostTimeoutScheduled) {
|
763 |
|
764 | cancelHostTimeout();
|
765 | } else {
|
766 | isHostTimeoutScheduled = true;
|
767 | }
|
768 |
|
769 |
|
770 | requestHostTimeout(handleTimeout, startTime - currentTime);
|
771 | }
|
772 | } else {
|
773 | newTask.sortIndex = expirationTime;
|
774 | push(taskQueue, newTask);
|
775 |
|
776 | if (enableProfiling) {
|
777 | markTaskStart(newTask, currentTime);
|
778 | newTask.isQueued = true;
|
779 | }
|
780 |
|
781 |
|
782 |
|
783 | if (!isHostCallbackScheduled && !isPerformingWork) {
|
784 | isHostCallbackScheduled = true;
|
785 | requestHostCallback(flushWork);
|
786 | }
|
787 | }
|
788 |
|
789 | return newTask;
|
790 | }
|
791 |
|
792 | function unstable_pauseExecution() {
|
793 | isSchedulerPaused = true;
|
794 | }
|
795 |
|
796 | function unstable_continueExecution() {
|
797 | isSchedulerPaused = false;
|
798 |
|
799 | if (!isHostCallbackScheduled && !isPerformingWork) {
|
800 | isHostCallbackScheduled = true;
|
801 | requestHostCallback(flushWork);
|
802 | }
|
803 | }
|
804 |
|
805 | function unstable_getFirstCallbackNode() {
|
806 | return peek(taskQueue);
|
807 | }
|
808 |
|
809 | function unstable_cancelCallback(task) {
|
810 | if (enableProfiling) {
|
811 | if (task.isQueued) {
|
812 | var currentTime = getCurrentTime();
|
813 | markTaskCanceled(task, currentTime);
|
814 | task.isQueued = false;
|
815 | }
|
816 | }
|
817 |
|
818 |
|
819 |
|
820 |
|
821 | task.callback = null;
|
822 | }
|
823 |
|
824 | function unstable_getCurrentPriorityLevel() {
|
825 | return currentPriorityLevel;
|
826 | }
|
827 |
|
828 | function unstable_shouldYield() {
|
829 | var currentTime = getCurrentTime();
|
830 | advanceTimers(currentTime);
|
831 | var firstTask = peek(taskQueue);
|
832 | return firstTask !== currentTask && currentTask !== null && firstTask !== null && firstTask.callback !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost();
|
833 | }
|
834 |
|
835 | var unstable_requestPaint = requestPaint;
|
836 | var unstable_Profiling = enableProfiling ? {
|
837 | startLoggingProfilingEvents: startLoggingProfilingEvents,
|
838 | stopLoggingProfilingEvents: stopLoggingProfilingEvents,
|
839 | sharedProfilingBuffer: sharedProfilingBuffer
|
840 | } : null;
|
841 |
|
842 | exports.unstable_flushAllWithoutAsserting = unstable_flushAllWithoutAsserting;
|
843 | exports.unstable_flushNumberOfYields = unstable_flushNumberOfYields;
|
844 | exports.unstable_flushExpired = unstable_flushExpired;
|
845 | exports.unstable_clearYields = unstable_clearYields;
|
846 | exports.unstable_flushUntilNextPaint = unstable_flushUntilNextPaint;
|
847 | exports.unstable_flushAll = unstable_flushAll;
|
848 | exports.unstable_yieldValue = unstable_yieldValue;
|
849 | exports.unstable_advanceTime = unstable_advanceTime;
|
850 | exports.unstable_ImmediatePriority = ImmediatePriority;
|
851 | exports.unstable_UserBlockingPriority = UserBlockingPriority;
|
852 | exports.unstable_NormalPriority = NormalPriority;
|
853 | exports.unstable_IdlePriority = IdlePriority;
|
854 | exports.unstable_LowPriority = LowPriority;
|
855 | exports.unstable_runWithPriority = unstable_runWithPriority;
|
856 | exports.unstable_next = unstable_next;
|
857 | exports.unstable_scheduleCallback = unstable_scheduleCallback;
|
858 | exports.unstable_cancelCallback = unstable_cancelCallback;
|
859 | exports.unstable_wrapCallback = unstable_wrapCallback;
|
860 | exports.unstable_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel;
|
861 | exports.unstable_shouldYield = unstable_shouldYield;
|
862 | exports.unstable_requestPaint = unstable_requestPaint;
|
863 | exports.unstable_continueExecution = unstable_continueExecution;
|
864 | exports.unstable_pauseExecution = unstable_pauseExecution;
|
865 | exports.unstable_getFirstCallbackNode = unstable_getFirstCallbackNode;
|
866 | exports.unstable_now = getCurrentTime;
|
867 | exports.unstable_forceFrameRate = forceFrameRate;
|
868 | exports.unstable_Profiling = unstable_Profiling;
|
869 | })();
|
870 | }
|