コード例 #1
0
ファイル: subscription.go プロジェクト: stampzilla/gocast
// Request works like send, but waits for resposne to requestId before returning
func (s *Subscription) Request(payload responses.Payload) (*api.CastMessage, error) {
	requestId := int(atomic.AddInt64(&s.requestId, 1))
	payload.SetRequestId(requestId)

	response := make(chan *api.CastMessage)
	s.inFlight[requestId] = response

	//err := s.Send(payload)
	err := s.Device.Send(s.Urn, s.SourceId, s.DestinationId, payload)
	if err != nil {
		delete(s.inFlight, requestId)
		return nil, err
	}

	select {
	case reply := <-response:
		return reply, nil
	case <-time.After(time.Second * 10):
		delete(s.inFlight, requestId)
		return nil, fmt.Errorf("Timeout sending: %s", spew.Sdump(payload))
	}
}
コード例 #2
0
ファイル: subscription.go プロジェクト: stampzilla/gocast
func (s *Subscription) Send(payload responses.Payload) error {
	requestId := int(atomic.AddInt64(&s.requestId, 1))
	payload.SetRequestId(requestId)
	return s.Device.Send(s.Urn, s.SourceId, s.DestinationId, payload)
}