NeoZephyr / Post-It-Note

0 stars 0 forks source link

生产与消费 #13

Open NeoZephyr opened 2 years ago

NeoZephyr commented 2 years ago
func (s *Service) consume() {
    defer func() {
        if x := recover(); x != nil {
            go s.consume()
        }
    }()
    for {
        f := <-s.tasks
        f()
    }
}

func (s *Service) produce(f func()) {
    select {
    case s.tasks <- f:
    default:
        log.Error("tasks full")
    }
}