Example #1
0
func (a *acceptor) Run() {
	defer a.Stopped()
	defer a.Listener.Close()

	for !a.StopRequested() {
		conn, err := a.Listener.Accept()
		if err == nil {
			a.NewAgent(conn)
		} else {
			ext.LogError(err)
			break
		}
	}
}
Example #2
0
func (r *stopper) Stop() {
	r.stopRequested = true
	timeout := make(chan bool)
	go func() {
		time.Sleep(2 * time.Second)
		timeout <- true
	}()
	select {
	case <-r.stopped:
		return
	case <-timeout:
		ext.LogError(errors.New("Timeout when stopping!"))
	}
}