Tighten
This commit is contained in:
parent
c8f040f3e4
commit
bea357d516
10
actor.ts
10
actor.ts
|
@ -70,7 +70,7 @@ type LocalAction = (t: Turn) => void;
|
||||||
export class Turn {
|
export class Turn {
|
||||||
readonly actor: Actor;
|
readonly actor: Actor;
|
||||||
readonly queues: Map<Actor, LocalAction[]> = new Map();
|
readonly queues: Map<Actor, LocalAction[]> = new Map();
|
||||||
readonly localActions: Array<LocalAction> = [];
|
readonly tasks: Array<LocalAction> = [];
|
||||||
|
|
||||||
static for(actor: Actor, f: (t: Turn) => void): void {
|
static for(actor: Actor, f: (t: Turn) => void): void {
|
||||||
const t = new Turn(actor);
|
const t = new Turn(actor);
|
||||||
|
@ -87,14 +87,14 @@ export class Turn {
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn(bootProc: (t: Turn) => void, initialAssertions = new IdentitySet<Handle>()): void {
|
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));
|
const child = new Actor(extractFromMap(this.actor.outbound, initialAssertions));
|
||||||
child.execute(() => Turn.for(child, bootProc));
|
child.execute(() => Turn.for(child, bootProc));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
quit(): void {
|
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 {
|
assert(location: Ref<Entity>, assertion: Assertion): Handle {
|
||||||
|
@ -138,9 +138,7 @@ export class Turn {
|
||||||
|
|
||||||
private complete(): void {
|
private complete(): void {
|
||||||
this.queues.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f))));
|
this.queues.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f))));
|
||||||
if (this.localActions.length > 0) {
|
this.tasks.length && queueMicrotask(() => this.tasks.forEach(f => Turn.for(this.actor, f)));
|
||||||
queueMicrotask(() => this.localActions.forEach(f => Turn.for(this.actor, f)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue