From 5aaa0946f701abb610f90426134b4a1e6bdd1e1e Mon Sep 17 00:00:00 2001 From: fuxiao <576101059@qq.com> Date: Fri, 1 Nov 2024 15:33:39 +0800 Subject: [PATCH] fixed bug of the actor's Destroy method --- cluster/node/actor.go | 13 ++++++++++++- cluster/node/scheduler.go | 4 +--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cluster/node/actor.go b/cluster/node/actor.go index edf9262..49ff50e 100644 --- a/cluster/node/actor.go +++ b/cluster/node/actor.go @@ -135,10 +135,19 @@ func (a *Actor) Push(uid int64, message *cluster.Message) { // Destroy 销毁Actor func (a *Actor) Destroy() { - if !a.state.CompareAndSwap(started, destroyed) { + if !a.destroy() { return } + a.scheduler.remove(a.Kind(), a.ID()) +} + +// 销毁Actor +func (a *Actor) destroy() bool { + if !a.state.CompareAndSwap(started, destroyed) { + return false + } + a.processor.Destroy() a.scheduler.batchUnbindActor(func(relations map[int64]map[string]*Actor) { @@ -154,6 +163,8 @@ func (a *Actor) Destroy() { close(a.mailbox) close(a.fnChan) + + return true } // 绑定用户 diff --git a/cluster/node/scheduler.go b/cluster/node/scheduler.go index 0639201..9804605 100644 --- a/cluster/node/scheduler.go +++ b/cluster/node/scheduler.go @@ -74,9 +74,7 @@ func (s *Scheduler) kill(kind, id string) bool { return false } - act.Destroy() - - return true + return act.destroy() } // 移除Actor