Skip to content

Commit

Permalink
Add helpful code comments to defer calls in sendTo and stop (#4394
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Andarist authored Oct 25, 2023
1 parent 6d50df4 commit d66200e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/core/src/actions/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ function executeSendTo(
return;
}

// this forms an outgoing events queue
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
actorContext.defer(() => {
const { to, event } = params;
actorContext?.system._relay(
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/actions/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ function executeStop(
if (!actorRef) {
return;
}
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
// this can happen, for example, when the invoking state is being exited immediately by an always transition
if (actorRef.status !== ActorStatus.Running) {
actorContext.stopChild(actorRef);
return;
}
// TODO: recheck why this one has to be deferred
// stopping a child enqueues a stop event in the child actor's mailbox
// we need for all of the already enqueued events to be processed before we stop the child
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
// and we don't want to ignore those events
actorContext.defer(() => {
actorContext.stopChild(actorRef);
});
Expand Down

0 comments on commit d66200e

Please sign in to comment.