diff --git a/CHANGELOG.md b/CHANGELOG.md index 91074fcb..6347454b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - add PostHTTPRequestPlugin - support io_uring - add CacheDiscovery +- add Oneshot method for XClient ## 1.8.0 diff --git a/client/client.go b/client/client.go index 5b121798..93ce78b6 100644 --- a/client/client.go +++ b/client/client.go @@ -262,17 +262,20 @@ func (client *Client) Go(ctx context.Context, servicePath, serviceMethod string, call.Args = args call.Reply = reply - if done == nil { - done = make(chan *Call, 10) // buffered. - } else { - // If caller passes done != nil, it must arrange that - // done has enough buffer for the number of simultaneous - // RPCs that will be using that channel. If the channel - // is totally unbuffered, it's best not to run at all. - if cap(done) == 0 { - log.Panic("rpc: done channel is unbuffered") - } - } + + // // we allow done is nil + // if done == nil { + // done = make(chan *Call, 10) // buffered. + // } else { + // // If caller passes done != nil, it must arrange that + // // done has enough buffer for the number of simultaneous + // // RPCs that will be using that channel. If the channel + // // is totally unbuffered, it's best not to run at all. + // if cap(done) == 0 { + // log.Panic("rpc: done channel is unbuffered") + // } + // } + call.Done = done if share.Trace { @@ -305,7 +308,7 @@ func (client *Client) call(ctx context.Context, servicePath, serviceMethod strin }() } - Done := client.Go(ctx, servicePath, serviceMethod, args, reply, make(chan *Call, 1)).Done + Done := client.Go(ctx, servicePath, serviceMethod, args, reply, make(chan *Call, 10)).Done var err error select { diff --git a/client/xclient.go b/client/xclient.go index 8b85426a..c383f6ad 100644 --- a/client/xclient.go +++ b/client/xclient.go @@ -54,6 +54,7 @@ type XClient interface { Go(ctx context.Context, serviceMethod string, args interface{}, reply interface{}, done chan *Call) (*Call, error) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error + Oneshot(ctx context.Context, serviceMethod string, args interface{}) error Broadcast(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error Fork(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error Inform(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) ([]Receipt, error) @@ -652,6 +653,13 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface } } +// Oneshot invokes the named function, ** DOEST NOT ** wait for it to complete, and returns immediately. +func (c *xClient) Oneshot(ctx context.Context, serviceMethod string, args interface{}) error { + _, err := c.Go(ctx, serviceMethod, args, nil, nil) + + return err +} + func uncoverError(err error) bool { if _, ok := err.(ServiceError); ok { return false