This commit is contained in:
Tony Garnock-Jones 2021-02-23 11:04:09 +01:00
parent c8f040f3e4
commit bea357d516
1 changed files with 4 additions and 6 deletions

View File

@ -70,7 +70,7 @@ type LocalAction = (t: Turn) => void;
export class Turn {
readonly actor: Actor;
readonly queues: Map<Actor, LocalAction[]> = new Map();
readonly localActions: Array<LocalAction> = [];
readonly tasks: Array<LocalAction> = [];
static for(actor: Actor, f: (t: Turn) => void): void {
const t = new Turn(actor);
@ -87,14 +87,14 @@ export class Turn {
}
spawn(bootProc: (t: Turn) => void, initialAssertions = new IdentitySet<Handle>()): void {
this.localActions.push(() => {
this.tasks.push(() => {
const child = new Actor(extractFromMap(this.actor.outbound, initialAssertions));
child.execute(() => Turn.for(child, bootProc));
});
}
quit(): void {
this.localActions.push(t => this.actor.terminateWith(t, { ok: true }));
this.tasks.push(t => this.actor.terminateWith(t, { ok: true }));
}
assert(location: Ref<Entity>, assertion: Assertion): Handle {
@ -138,9 +138,7 @@ export class Turn {
private complete(): void {
this.queues.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f))));
if (this.localActions.length > 0) {
queueMicrotask(() => this.localActions.forEach(f => Turn.for(this.actor, f)));
}
this.tasks.length && queueMicrotask(() => this.tasks.forEach(f => Turn.for(this.actor, f)));
}
}