// WithContext constructs and returns a Process that respects // given context. It is the equivalent of: // // func ProcessWithContext(ctx context.Context) goprocess.Process { // p := goprocess.WithParent(goprocess.Background()) // go func() { // <-ctx.Done() // p.Close() // }() // return p // } // func WithContext(ctx context.Context) goprocess.Process { if ctx == nil { panic("nil Context") } p := goprocess.WithParent(goprocess.Background()) go func() { <-ctx.Done() p.Close() }() return p }
func NewWorker(e exchange.Interface, c Config) *Worker { if c.NumWorkers < 1 { c.NumWorkers = 1 // provide a sane default } w := &Worker{ exchange: e, added: make(chan *blocks.Block, c.ClientBufferSize), process: process.WithParent(process.Background()), // internal management } w.start(c) return w }
func NewRateLimiter(parent process.Process, limit int) *RateLimiter { proc := process.WithParent(parent) return &RateLimiter{Process: proc, limiter: LimitChan(limit)} }