| 97 | } |
| 98 | |
| 99 | export function queueJob(job: SchedulerJob): void { |
| 100 | if (!(job.flags! & SchedulerJobFlags.QUEUED)) { |
| 101 | const jobId = getId(job) |
| 102 | const lastJob = queue[queue.length - 1] |
| 103 | if ( |
| 104 | !lastJob || |
| 105 | // fast path when the job id is larger than the tail |
| 106 | (!(job.flags! & SchedulerJobFlags.PRE) && jobId >= getId(lastJob)) |
| 107 | ) { |
| 108 | queue.push(job) |
| 109 | } else { |
| 110 | queue.splice(findInsertionIndex(jobId), 0, job) |
| 111 | } |
| 112 | |
| 113 | job.flags! |= SchedulerJobFlags.QUEUED |
| 114 | |
| 115 | queueFlush() |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | function queueFlush() { |
| 120 | if (!currentFlushPromise) { |