package rest_websocket import ( "log" "time" "git.ali33.ru/fcg-xvii/rest" ) func newWaitRequest(id int64, timeout time.Time) *waitRequest { now := time.Now() if timeout.Before(now) { timeout = now.Add(time.Second * 10) } res := &waitRequest{ id: id, answer: make(chan *rest.RequestStream, 1), answerIn: make(chan *rest.RequestStream, 1), timeout: timeout, } go res.exec() return res } type waitRequest struct { id int64 answer chan *rest.RequestStream answerIn chan *rest.RequestStream timeout time.Time } func (s *waitRequest) exec() { select { case answ, ok := <-s.answerIn: if !ok { close(s.answer) return } s.answer <- answ case <-time.After(s.timeout.Sub(time.Now())): log.Println("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR") close(s.answer) } }