Skip to content

Commit

Permalink
Merge pull request #934 from nightwolfz/dev
Browse files Browse the repository at this point in the history
Allow poisoning router actors
  • Loading branch information
rogeralsing authored Nov 21, 2023
2 parents 7ecca73 + 2fb1365 commit 1b57a1f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions router/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ var _ actor.Process = &process{}

func (ref *process) SendUserMessage(pid *actor.PID, message interface{}) {
_, msg, _ := actor.UnwrapEnvelope(message)

// Add support for PoisonPill. Originally only Stop is supported.
if _, ok := msg.(*actor.PoisonPill); ok {
ref.Poison(pid)
return
}
if _, ok := msg.(ManagementMessage); !ok {
ref.state.RouteMessage(message)
} else {
Expand Down Expand Up @@ -85,3 +91,13 @@ func (ref *process) Stop(pid *actor.PID) {
ref.actorSystem.ProcessRegistry.Remove(pid)
ref.SendSystemMessage(pid, &actor.Stop{})
}

func (ref *process) Poison(pid *actor.PID) {
if atomic.SwapInt32(&ref.stopping, 1) == 1 {
return
}

_ = ref.actorSystem.Root.PoisonFuture(ref.router).Wait()
ref.actorSystem.ProcessRegistry.Remove(pid)
ref.SendSystemMessage(pid, &actor.Stop{})
}

0 comments on commit 1b57a1f

Please sign in to comment.