コード例 #1
0
ファイル: actor.go プロジェクト: morikuni/flower
func (actor *actor) start() {
	actor.mu.Lock()
	defer actor.mu.Unlock()
	if actor.running {
		return
	}
	actor.running = true
	log.Debug(actor.path, "start")
	go func() {
		defer func() {
			actor.mu.Lock()
			actor.running = false
			log.Debug(actor.path, "stop")
			actor.mu.Unlock()

			err := recover()
			if err != nil {
				p := Panic{
					Actor:  actor,
					Reason: err,
				}

				log.Error(actor.path, "panic")
				for _, m := range actor.monitors {
					m.Send() <- p
				}
			} else {
				actor.stoppedChan <- struct{}{}
			}
		}()

	LOOP:
		for {
			select {
			case <-actor.stopChan:
				break LOOP
			case msg := <-actor.msgChan:
				actor.receive(msg)
			}
		}
	}()
}
コード例 #2
0
ファイル: guardian.go プロジェクト: morikuni/flower
func (g *guardian) receive(msg Message) {
	log.Error("Guardian received:", msg)
}