1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

Fix the error returns from done and bail early if we dont have time

This commit is contained in:
Asim 2016-05-12 23:56:25 +01:00
parent 00a26677b8
commit b6f5e15362

View File

@ -109,7 +109,7 @@ func (r *rpcClient) call(ctx context.Context, address string, req Request, resp
case err := <-ch: case err := <-ch:
return err return err
case <-ctx.Done(): case <-ctx.Done():
return errors.New("go.micro.client", ctx.Err(), 408) return errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
} }
} }
@ -159,7 +159,7 @@ func (r *rpcClient) stream(ctx context.Context, address string, req Request, opt
case err := <-ch: case err := <-ch:
grr = err grr = err
case <-ctx.Done(): case <-ctx.Done():
grr = errors.New("go.micro.client", ctx.Err(), 408) grr = errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
} }
if grr != nil { if grr != nil {
@ -217,6 +217,13 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
opt(&callOpts) opt(&callOpts)
} }
// should we noop right here?
select {
case <-ctx.Done():
return errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
default:
}
// return errors.New("go.micro.client", "request timeout", 408) // return errors.New("go.micro.client", "request timeout", 408)
call := func(i int) error { call := func(i int) error {
// call backoff first. Someone may want an initial start delay // call backoff first. Someone may want an initial start delay
@ -260,7 +267,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
select { select {
case <-ctx.Done(): case <-ctx.Done():
return errors.New("go.micro.client", ctx.Err(), 408) return errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
case err := <-ch: case err := <-ch:
// if the call succeeded lets bail early // if the call succeeded lets bail early
if err == nil { if err == nil {
@ -309,6 +316,13 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
opt(&callOpts) opt(&callOpts)
} }
// should we noop right here?
select {
case <-ctx.Done():
return nil, errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
default:
}
call := func(i int) (Streamer, error) { call := func(i int) (Streamer, error) {
// call backoff first. Someone may want an initial start delay // call backoff first. Someone may want an initial start delay
t, err := callOpts.Backoff(ctx, request, i) t, err := callOpts.Backoff(ctx, request, i)
@ -354,7 +368,7 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
select { select {
case <-ctx.Done(): case <-ctx.Done():
return nil, errors.New("go.micro.client", ctx.Err(), 408) return nil, errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
case rsp := <-ch: case rsp := <-ch:
// if the call succeeded lets bail early // if the call succeeded lets bail early
if rsp.err == nil { if rsp.err == nil {