Match-id-1f58ff819dfbd01d0b80fd9bfaa198bcb73f0b50
This commit is contained in:
parent
e26d0e0fd7
commit
cadaabfd3b
|
@ -19,11 +19,9 @@
|
|||
|
||||
let isMessageLoopRunning = false;
|
||||
let browserCallback = null;
|
||||
const { port1, port2 } = new MessageChannel();
|
||||
|
||||
export function isOverTime() {
|
||||
return false;
|
||||
}
|
||||
let port1 = null;
|
||||
let port2 = null;
|
||||
let isTestRuntime = false;
|
||||
|
||||
// 1、设置deadline;2、回调TaskExecutor传过来的browserCallback
|
||||
const callRenderTasks = () => {
|
||||
|
@ -41,21 +39,38 @@ const callRenderTasks = () => {
|
|||
browserCallback = null;
|
||||
} else {
|
||||
// 还有task,继续调用
|
||||
port2.postMessage(null);
|
||||
asyncCall();
|
||||
}
|
||||
} catch (error) {
|
||||
port2.postMessage(null);
|
||||
asyncCall();
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
port1.onmessage = callRenderTasks;
|
||||
if (typeof MessageChannel === 'function') {
|
||||
const mc = new MessageChannel();
|
||||
port1 = mc.port1;
|
||||
port1.onmessage = callRenderTasks;
|
||||
port2 = mc.port2;
|
||||
} else {
|
||||
// 测试环境没有 MessageChannel
|
||||
isTestRuntime = true;
|
||||
}
|
||||
|
||||
function asyncCall() {
|
||||
if (isTestRuntime) {
|
||||
setTimeout(callRenderTasks, 0);
|
||||
} else {
|
||||
port2.postMessage(null);
|
||||
}
|
||||
}
|
||||
|
||||
export function requestBrowserCallback(callback) {
|
||||
browserCallback = callback;
|
||||
|
||||
if (!isMessageLoopRunning) {
|
||||
isMessageLoopRunning = true;
|
||||
port2.postMessage(null);
|
||||
asyncCall();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import { Node } from '../taskExecutor/TaskQueue';
|
||||
import { requestBrowserCallback, isOverTime } from './BrowserAsync';
|
||||
import { requestBrowserCallback } from './BrowserAsync';
|
||||
|
||||
import { add, shift, first, remove } from './TaskQueue';
|
||||
|
||||
|
@ -44,11 +44,6 @@ function callTasks() {
|
|||
|
||||
// 循环执行task
|
||||
while (task !== null) {
|
||||
if (isOverTime()) {
|
||||
// 超过了deadline
|
||||
break;
|
||||
}
|
||||
|
||||
const callback = task.callback;
|
||||
if (callback !== null) {
|
||||
task.callback = null;
|
||||
|
|
Loading…
Reference in New Issue