Stop 停止 Actor
(pid *PID)
| 328 | |
| 329 | // Stop 停止 Actor |
| 330 | func (s *System) Stop(pid *PID) { |
| 331 | s.actorsMu.RLock() |
| 332 | cell, exists := s.actors[pid.ID] |
| 333 | s.actorsMu.RUnlock() |
| 334 | |
| 335 | if !exists { |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | // 发送 PoisonPill |
| 340 | s.Send(pid, &PoisonPill{}) |
| 341 | |
| 342 | // 等待停止完成 |
| 343 | cell.stateMu.Lock() |
| 344 | cell.state = actorStateStopping |
| 345 | cell.stateMu.Unlock() |
| 346 | } |
| 347 | |
| 348 | // StopGracefully 优雅停止 Actor(等待处理完当前消息) |
| 349 | func (s *System) StopGracefully(pid *PID, timeout time.Duration) error { |