@@ -15,6 +15,7 @@ import (
1515 "go.unistack.org/micro/v3/codec"
1616 "go.unistack.org/micro/v3/errors"
1717 "go.unistack.org/micro/v3/metadata"
18+ "go.unistack.org/micro/v3/selector"
1819 "storj.io/drpc/drpcconn"
1920 dmetadata "storj.io/drpc/drpcmetadata"
2021)
@@ -401,18 +402,7 @@ func (d *drpcClient) Call(ctx context.Context, req client.Request, rsp interface
401402 callOpts .Address = []string {d .opts .Proxy }
402403 }
403404
404- // lookup the route to send the reques to
405- // TODO apply any filtering here
406- routes , err := d .opts .Lookup (ctx , req , callOpts )
407- if err != nil {
408- return errors .InternalServerError ("go.micro.client" , err .Error ())
409- }
410-
411- // balance the list of nodes
412- next , err := callOpts .Selector .Select (routes )
413- if err != nil {
414- return err
415- }
405+ var next selector.Next
416406
417407 // return errors.New("go.micro.client", "request timeout", 408)
418408 call := func (i int ) error {
@@ -427,6 +417,23 @@ func (d *drpcClient) Call(ctx context.Context, req client.Request, rsp interface
427417 time .Sleep (t )
428418 }
429419
420+ if next == nil {
421+ var routes []string
422+
423+ // lookup the route to send the reques to
424+ // TODO apply any filtering here
425+ routes , err = d .opts .Lookup (ctx , req , callOpts )
426+ if err != nil {
427+ return errors .InternalServerError ("go.micro.client" , err .Error ())
428+ }
429+
430+ // balance the list of nodes
431+ next , err = callOpts .Selector .Select (routes )
432+ if err != nil {
433+ return err
434+ }
435+ }
436+
430437 // get the next node
431438 node := next ()
432439
@@ -520,18 +527,7 @@ func (g *drpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
520527 callOpts.Address = []string{g.opts.Proxy}
521528 }
522529
523- // lookup the route to send the reques to
524- // TODO: move to internal lookup func
525- routes, err := g.opts.Lookup(ctx, req, callOpts)
526- if err != nil {
527- return nil, errors.InternalServerError("go.micro.client", err.Error())
528- }
529-
530- // balance the list of nodes
531- next, err := callOpts.Selector.Select(routes)
532- if err != nil {
533- return nil, err
534- }
530+ var next selector.Next
535531
536532 call := func(i int) (client.Stream, error) {
537533 // call backoff first. Someone may want an initial start delay
@@ -545,6 +541,23 @@ func (g *drpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
545541 time.Sleep(t)
546542 }
547543
544+ if next == nil {
545+ var routes []string
546+
547+ // lookup the route to send the reques to
548+ // TODO apply any filtering here
549+ routes, err = d.opts.Lookup(ctx, req, callOpts)
550+ if err != nil {
551+ return nil, errors.InternalServerError("go.micro.client", err.Error())
552+ }
553+
554+ // balance the list of nodes
555+ next, err := callOpts.Selector.Select(routes)
556+ if err != nil {
557+ return nil, err
558+ }
559+ }
560+
548561 // get the next node
549562 node := next()
550563
0 commit comments