mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
NoResponse service
This commit is contained in:

committed by
Brian Tiger Chow

parent
69b1ce42d9
commit
25d0ce8fdd
@ -10,6 +10,10 @@ import (
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
)
|
||||
|
||||
// ErrNoResponse is returned by Service when a Request did not get a response,
|
||||
// and no other error happened
|
||||
var ErrNoResponse = errors.New("no response to request")
|
||||
|
||||
// Handler is an interface that objects must implement in order to handle
|
||||
// a service's requests.
|
||||
type Handler interface {
|
||||
@ -134,6 +138,10 @@ func (s *Service) SendRequest(ctx context.Context, m msg.NetMessage) (msg.NetMes
|
||||
err = ctx.Err()
|
||||
}
|
||||
|
||||
if m == nil {
|
||||
return nil, ErrNoResponse
|
||||
}
|
||||
|
||||
return m, err
|
||||
}
|
||||
|
||||
@ -205,6 +213,7 @@ func (s *Service) handleIncomingMessage(ctx context.Context, m msg.NetMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetHandler assigns the request Handler for this service.
|
||||
func (s *Service) SetHandler(h Handler) {
|
||||
s.Handler = h
|
||||
}
|
||||
|
Reference in New Issue
Block a user