mirror of
https://github.com/containous/traefik.git
synced 2025-03-25 14:50:11 +03:00
Adds Cleanup method to safe.Pool
This commit is contained in:
parent
8ae9607d9b
commit
66e914a8ab
@ -21,18 +21,20 @@ type Pool struct {
|
||||
waitGroup sync.WaitGroup
|
||||
lock sync.Mutex
|
||||
baseCtx context.Context
|
||||
baseCancel context.CancelFunc
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
// NewPool creates a Pool
|
||||
func NewPool(parentCtx context.Context) *Pool {
|
||||
baseCtx, _ := context.WithCancel(parentCtx)
|
||||
baseCtx, baseCancel := context.WithCancel(parentCtx)
|
||||
ctx, cancel := context.WithCancel(baseCtx)
|
||||
return &Pool{
|
||||
baseCtx: baseCtx,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
baseCtx: baseCtx,
|
||||
baseCancel: baseCancel,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,6 +92,14 @@ func (p *Pool) Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup releases resources used by the pool, and should be called when the pool will no longer be used
|
||||
func (p *Pool) Cleanup() {
|
||||
p.Stop()
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.baseCancel()
|
||||
}
|
||||
|
||||
// Start starts all stopped routines
|
||||
func (p *Pool) Start() {
|
||||
p.lock.Lock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user