The local tasks are just another queue
This commit is contained in:
parent
4045d0d0ed
commit
5669154e96
11
actor.ts
11
actor.ts
|
@ -80,13 +80,11 @@ type LocalAction = (t: Turn) => void;
|
|||
export class Turn {
|
||||
readonly actor: Actor;
|
||||
readonly queues: Map<Actor, LocalAction[]> = new Map();
|
||||
readonly tasks: Array<LocalAction> = [];
|
||||
|
||||
static for(actor: Actor, f: LocalAction): void {
|
||||
const t = new Turn(actor);
|
||||
f(t);
|
||||
t.queues.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f))));
|
||||
t.tasks.length && queueMicrotask(() => t.tasks.forEach(f => Turn.for(actor, f)));
|
||||
}
|
||||
|
||||
private constructor(actor: Actor) {
|
||||
|
@ -98,7 +96,7 @@ export class Turn {
|
|||
}
|
||||
|
||||
spawn(bootProc: LocalAction, initialAssertions = new IdentitySet<Handle>()): void {
|
||||
this.enqueue(void 0, () => {
|
||||
this.enqueue(this.actor, () => {
|
||||
const newOutbound: OutboundMap = new Map();
|
||||
initialAssertions.forEach(key => {
|
||||
newOutbound.set(key, this.actor.outbound.get(key)!); // we trust initialAssertions
|
||||
|
@ -110,7 +108,7 @@ export class Turn {
|
|||
}
|
||||
|
||||
quit(): void {
|
||||
this.enqueue(void 0, t => this.actor.terminateWith(t, { ok: true }));
|
||||
this.enqueue(this.actor, t => this.actor.terminateWith(t, { ok: true }));
|
||||
}
|
||||
|
||||
assert(ref: Ref, assertion: Assertion): Handle {
|
||||
|
@ -148,8 +146,7 @@ export class Turn {
|
|||
this.enqueue(ref.relay, t => ref[message]?.(t, assertion));
|
||||
}
|
||||
|
||||
enqueue(relay: Actor | undefined, a: LocalAction): void {
|
||||
(relay === void 0) ? this.tasks.push(a)
|
||||
: this.queues.get(relay)?.push(a) ?? this.queues.set(relay, [a]);
|
||||
enqueue(relay: Actor, a: LocalAction): void {
|
||||
this.queues.get(relay)?.push(a) ?? this.queues.set(relay, [a]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue