Move exception handling to the right place: inside each turn
This commit is contained in:
parent
01fb3a471a
commit
81a307e03c
34
src/actor.ts
34
src/actor.ts
|
@ -125,20 +125,10 @@ export class Actor {
|
||||||
console.error(`Actor ${this.id} crashed:`, this.exitReason.err);
|
console.error(`Actor ${this.id} crashed:`, this.exitReason.err);
|
||||||
}
|
}
|
||||||
this.exitHooks.forEach(hook => hook(t));
|
this.exitHooks.forEach(hook => hook(t));
|
||||||
queueTask(() =>
|
queueTask(() => Turn.for(
|
||||||
t.freshen(t =>
|
t.actor,
|
||||||
this.outbound.forEach((peer, h) => t._retract(peer, h))));
|
t => this.outbound.forEach((peer, h) => t._retract(peer, h)),
|
||||||
}
|
true));
|
||||||
|
|
||||||
execute(proc: () => void): void {
|
|
||||||
queueTask(() => {
|
|
||||||
if (this.exitReason !== null) return;
|
|
||||||
try {
|
|
||||||
proc();
|
|
||||||
} catch (err) {
|
|
||||||
Turn.for(this, t => this.terminateWith(t, { ok: false, err }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,11 +148,16 @@ export class Turn {
|
||||||
readonly actor: Actor;
|
readonly actor: Actor;
|
||||||
queues: Map<Actor, LocalAction[]> | null = new Map();
|
queues: Map<Actor, LocalAction[]> | null = new Map();
|
||||||
|
|
||||||
static for(actor: Actor, f: LocalAction): void {
|
static for(actor: Actor, f: LocalAction, zombieTurn = false): void {
|
||||||
|
if ((actor.exitReason === null) === zombieTurn) return;
|
||||||
const t = new Turn(actor);
|
const t = new Turn(actor);
|
||||||
f(t);
|
try {
|
||||||
t.queues!.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f))));
|
f(t);
|
||||||
t.queues = null;
|
t.queues!.forEach((q, a) => queueTask(() => q.forEach(f => Turn.for(a, f))));
|
||||||
|
t.queues = null;
|
||||||
|
} catch (err) {
|
||||||
|
Turn.for(actor, t => actor.terminateWith(t, { ok: false, err }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor(actor: Actor) {
|
private constructor(actor: Actor) {
|
||||||
|
@ -180,8 +175,7 @@ export class Turn {
|
||||||
newOutbound.set(key, this.actor.outbound.get(key)!); // we trust initialAssertions
|
newOutbound.set(key, this.actor.outbound.get(key)!); // we trust initialAssertions
|
||||||
this.actor.outbound.delete(key);
|
this.actor.outbound.delete(key);
|
||||||
});
|
});
|
||||||
const child = new Actor(newOutbound);
|
queueTask(() => Turn.for(new Actor(newOutbound), bootProc));
|
||||||
child.execute(() => Turn.for(child, bootProc));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue