// Start launches the pool, making it ready to accept submissions.
Start launches the pool, making it ready to accept submissions.
// Start launches the pool making it ready to accept submissions .
func (p *LimitingExecutor) Start() {
	p.lock.Lock()
	defer p.lock.Unlock()
	if p.ingest == nil {
		var (
			ingest = make(chan func())
			queue  []func()
		)
		p.ingest = ingest
		go func() {
			var (
				current int
				wg      sync.WaitGroup
				done    = make(chan struct{})
			)
			defer close(done)
		Loop:
			for {
				select {
				case <-done:
					current--
				case f, ok := <-ingest:
					if !ok {
						break Loop
					}
					queue = append(queue, f)
				default:
					if len(queue) > 0 && current < p.maxRunning {
						current++
						f := queue[0]
						queue = queue[1:]
						wg.Add(1)
						p.executor.Submit(func() {
							defer wg.Done()
							f()
							done <- struct{}{}
						})
					}
				}
			}
			wg.Wait()
		}()
	}
}
func ( p * LimitingExecutor ) Start ( ) { p . lock . Lock ( ) defer p . lock . Unlock ( ) if p . ingest == nil { var ( ingest = make ( chan func ( ) ) queue [ ] func ( ) ) p . ingest = ingest go func ( ) { var ( current int wg sync . WaitGroup done = make ( chan struct { } ) ) defer close ( done ) Loop : for { select { case <- done : current -- case f , ok := <- ingest : if ! ok { break Loop } queue = append ( queue , f ) default : if len ( queue ) > 0 && current < p . maxRunning { current ++ f := queue [ 0 ] queue = queue [ 1 : ] wg . Add ( 1 ) p . executor . Submit ( func ( ) { defer wg . Done ( ) f ( ) done <- struct { } { } } ) } } } wg . Wait ( ) } ( ) } }
Start launches the pool, making it ready to accept submissions.
Start launches the pool making it ready to accept submissions .