- Published on
调度
- Authors

- Name
- 李丹秋
export function finishQueueingConcurrentUpdates(): void {
const endIndex = concurrentQueuesIndex;
concurrentQueuesIndex = 0;
concurrentlyUpdatedLanes = NoLanes;
let i = 0;
while (i < endIndex) {
const fiber: Fiber = concurrentQueues[i];
concurrentQueues[i++] = null;
const queue: ConcurrentQueue = concurrentQueues[i];
concurrentQueues[i++] = null;
const update: ConcurrentUpdate = concurrentQueues[i];
concurrentQueues[i++] = null;
const lane: Lane = concurrentQueues[i];
concurrentQueues[i++] = null;
if (queue !== null && update !== null) {
const pending = queue.pending;
// 每次循环,同一个hook的queue是相同的
if (pending === null) {
// This is the first update. Create a circular list.
update.next = update;
} else {
// Append the update to the end of the list.
update.next = pending.next;
pending.next = update;
}
queue.pending = update;
}
if (lane !== NoLane) {
markUpdateLaneFromFiberToRoot(fiber, update, lane);
}
}
}
一个hook维护一个队列,这个队列是一个循环队列,每次调度任务的开始,都会执行上面的方法。这个方法主要做两件事情:
每次调度任务的开始,都会执行上面的方法。这个方法主要做两件事情:
- 创建update链表, 通过
update.next指向下一个update - 标记更新的优先级, 通过
markUpdateLaneFromFiberToRoot方法标记更新的优先级