MCPcopy Create free account
hub / github.com/astercloud/aster / StopGracefully

Method StopGracefully

pkg/actor/system.go:349–375  ·  view source on GitHub ↗

StopGracefully 优雅停止 Actor(等待处理完当前消息)

(pid *PID, timeout time.Duration)

Source from the content-addressed store, hash-verified

347
348// StopGracefully 优雅停止 Actor(等待处理完当前消息)
349func (s *System) StopGracefully(pid *PID, timeout time.Duration) error {
350 s.Stop(pid)
351
352 // 等待状态变为 stopped
353 deadline := time.Now().Add(timeout)
354 for time.Now().Before(deadline) {
355 s.actorsMu.RLock()
356 cell, exists := s.actors[pid.ID]
357 s.actorsMu.RUnlock()
358
359 if !exists {
360 return nil
361 }
362
363 cell.stateMu.RLock()
364 state := cell.state
365 cell.stateMu.RUnlock()
366
367 if state == actorStateStopped {
368 return nil
369 }
370
371 time.Sleep(10 * time.Millisecond)
372 }
373
374 return fmt.Errorf("timeout waiting for actor %s to stop", pid.ID)
375}
376
377// Shutdown 关闭整个 Actor 系统
378func (s *System) Shutdown() {

Callers

nothing calls this directly

Calls 2

StopMethod · 0.95
AddMethod · 0.65

Tested by

no test coverage detected