Receive 处理消息
(ctx *Context, msg Message)
| 354 | |
| 355 | // Receive 处理消息 |
| 356 | func (s *SupervisorActor) Receive(ctx *Context, msg Message) { |
| 357 | switch m := msg.(type) { |
| 358 | case *Started: |
| 359 | // 启动所有子 Actor |
| 360 | for _, spec := range s.config.Children { |
| 361 | child := spec.Factory() |
| 362 | props := spec.Props |
| 363 | if props == nil { |
| 364 | props = DefaultProps(spec.Name) |
| 365 | } |
| 366 | props.SupervisorStrategy = s.config.Strategy |
| 367 | pid := ctx.SpawnWithProps(child, props) |
| 368 | s.children[spec.Name] = pid |
| 369 | } |
| 370 | |
| 371 | case *Terminated: |
| 372 | // 子 Actor 终止,根据策略处理 |
| 373 | delete(s.children, m.Who.ID) |
| 374 | |
| 375 | case *Stopping: |
| 376 | // 停止所有子 Actor |
| 377 | for _, pid := range s.children { |
| 378 | ctx.Stop(pid) |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // GetChild 获取子 Actor |
| 384 | func (s *SupervisorActor) GetChild(name string) *PID { |
nothing calls this directly
no test coverage detected