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);
|
||||
}
|
||||
this.exitHooks.forEach(hook => hook(t));
|
||||
queueTask(() =>
|
||||
t.freshen(t =>
|
||||
this.outbound.forEach((peer, h) => t._retract(peer, h))));
|
||||
}
|
||||
|
||||
execute(proc: () => void): void {
|
||||
queueTask(() => {
|
||||
if (this.exitReason !== null) return;
|
||||
try {
|
||||
proc();
|
||||
} catch (err) {
|
||||
Turn.for(this, t => this.terminateWith(t, { ok: false, err }));
|
||||
}
|
||||
});
|
||||
queueTask(() => Turn.for(
|
||||
t.actor,
|
||||
t => this.outbound.forEach((peer, h) => t._retract(peer, h)),
|
||||
true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,11 +148,16 @@ export class Turn {
|
|||
readonly actor: Actor;
|
||||
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);
|
||||
f(t);
|
||||
t.queues!.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f))));
|
||||
t.queues = null;
|
||||
try {
|
||||
f(t);
|
||||
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) {
|
||||
|
@ -180,8 +175,7 @@ export class Turn {
|
|||
newOutbound.set(key, this.actor.outbound.get(key)!); // we trust initialAssertions
|
||||
this.actor.outbound.delete(key);
|
||||
});
|
||||
const child = new Actor(newOutbound);
|
||||
child.execute(() => Turn.for(child, bootProc));
|
||||
queueTask(() => Turn.for(new Actor(newOutbound), bootProc));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue