예제 #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)
}