We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func main() { e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { log.Fatal(err) } pid := e.Spawn(newServer, "server", actor.WithID("server")) sigchld := make(chan os.Signal, 1) signal.Notify(sigchld, syscall.SIGINT, syscall.SIGTERM) <-sigchld wg := &sync.WaitGroup{} e.Poison(pid, wg) wg.Wait() } type Server struct { } func newServer() actor.Receiver { return &Server{} } func (s *Server) Receive(c *actor.Context) { switch msg := c.Message().(type) { case actor.Initialized: fmt.Println("server initialized") case actor.Started: fmt.Println("server started") for i := 0; i < 1; i++ { pid := c.SpawnChild(newServerChild(c.PID()), "client", actor.WithID(uuid.New().String())) //wg := &sync.WaitGroup{} //c.Engine().Poison(pid, wg) //wg.Wait() c.Engine().Poison(pid) //TODO: how can i close this pid time.Sleep(time.Second) fmt.Println(pid) } case actor.Stopped: fmt.Println("server stopped") case *actor.PID: //c.Engine().Poison(c.Sender()) default: fmt.Printf("%v\n", msg) } } type ServerChild struct { ServerPid *actor.PID } func newServerChild(ServerPid *actor.PID) actor.Producer { return func() actor.Receiver { return &ServerChild{ ServerPid: ServerPid, } } } func (sc *ServerChild) Receive(c *actor.Context) { switch msg := c.Message().(type) { case actor.Initialized: fmt.Println("serverChild initialized") case actor.Started: fmt.Println("serverChild started") //c.SpawnChild(newTimer(), "Timer") case actor.Stopped: fmt.Println("serverChild stopped") case *actor.PID: fmt.Println("serverChild got timer") default: fmt.Printf("%v\n", msg) } }
This code will deadlock when poison server's pid, how should I gracefully close a pid from SpawnChild?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
This code will deadlock when poison server's pid, how should I gracefully close a pid from SpawnChild?
The text was updated successfully, but these errors were encountered: