Fix(picker): add WithTimeout for some situation
This commit is contained in:
@ -3,6 +3,7 @@ package picker
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Picker provides synchronization, and Context cancelation
|
||||
@ -18,11 +19,19 @@ type Picker struct {
|
||||
}
|
||||
|
||||
// WithContext returns a new Picker and an associated Context derived from ctx.
|
||||
// and cancel when first element return.
|
||||
func WithContext(ctx context.Context) (*Picker, context.Context) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
return &Picker{cancel: cancel}, ctx
|
||||
}
|
||||
|
||||
// WithTimeout returns a new Picker and an associated Context derived from ctx with timeout,
|
||||
// but it doesn't cancel when first element return.
|
||||
func WithTimeout(ctx context.Context, timeout time.Duration) (*Picker, context.Context, context.CancelFunc) {
|
||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||
return &Picker{}, ctx, cancel
|
||||
}
|
||||
|
||||
// Wait blocks until all function calls from the Go method have returned,
|
||||
// then returns the first nil error result (if any) from them.
|
||||
func (p *Picker) Wait() interface{} {
|
||||
|
Reference in New Issue
Block a user