Skip to content

Commit

Permalink
feat(scheduler): add repeat parameter to yieldAll for dirty checker etc
Browse files Browse the repository at this point in the history
  • Loading branch information
fkleuver committed Oct 26, 2019
1 parent 992099f commit 9f24306
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
16 changes: 9 additions & 7 deletions packages/runtime-html-browser/src/browser-scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-await-in-loop */
import { IContainer, bound } from '@aurelia/kernel';
import { IDOM, IScheduler, TaskQueuePriority, TaskQueue, IClock, TaskCallback, QueueTaskOptions, Task, DOM, ITaskQueue, ITask, QueueTaskTargetOptions } from '@aurelia/runtime';
import { HTMLDOM } from '@aurelia/runtime-html';
Expand Down Expand Up @@ -453,17 +454,18 @@ export class BrowserScheduler implements IScheduler {
return this.taskQueue[TaskQueuePriority.idle].yield();
}
@bound
public yieldAll(): Promise<void> {
public async yieldAll(repeat: number = 1): Promise<void> {
// Yield sequentially from "large" to "small" so that any smaller tasks initiated by larger tasks are also still awaited,
// as well as guaranteeing a single round of persistent tasks from each queue.
// Don't change the order or into parallel, without thoroughly testing the ramifications on persistent and recursively queued tasks.
// These aspects are currently relatively poorly tested.
return Promise.resolve()
.then(this.yieldIdleTask)
.then(this.yieldPostRenderTask)
.then(this.yieldMacroTask)
.then(this.yieldRenderTask)
.then(this.yieldMicroTask);
while (repeat-- > 0) {
await this.yieldIdleTask();
await this.yieldPostRenderTask();
await this.yieldMacroTask();
await this.yieldRenderTask();
await this.yieldMicroTask();
}
}

public queueMicroTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T> {
Expand Down
16 changes: 9 additions & 7 deletions packages/runtime-html-jsdom/src/jsdom-scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-await-in-loop */
import { IContainer, PLATFORM, bound } from '@aurelia/kernel';
import { IDOM, QueueTaskOptions, TaskQueuePriority, IScheduler, TaskQueue, IClock, TaskCallback, Task, DOM, ITaskQueue, ITask, QueueTaskTargetOptions } from '@aurelia/runtime';
import { HTMLDOM } from '@aurelia/runtime-html';
Expand Down Expand Up @@ -396,13 +397,14 @@ export class JSDOMScheduler implements IScheduler {
return this.taskQueue[TaskQueuePriority.idle].yield();
}
@bound
public yieldAll(): Promise<void> {
return Promise.resolve()
.then(this.yieldIdleTask)
.then(this.yieldPostRenderTask)
.then(this.yieldMacroTask)
.then(this.yieldRenderTask)
.then(this.yieldMicroTask);
public async yieldAll(repeat: number = 1): Promise<void> {
while (repeat-- > 0) {
await this.yieldIdleTask();
await this.yieldPostRenderTask();
await this.yieldMacroTask();
await this.yieldRenderTask();
await this.yieldMicroTask();
}
}

public queueMicroTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T> {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export interface IScheduler {
yieldMacroTask(): Promise<void>;
yieldPostRenderTask(): Promise<void>;
yieldIdleTask(): Promise<void>;
yieldAll(): Promise<void>;
yieldAll(repeat?: number): Promise<void>;

queueMicroTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
queueRenderTask<T = any>(callback: TaskCallback<T>, opts?: QueueTaskOptions): ITask<T>;
Expand Down

0 comments on commit 9f24306

Please sign in to comment.