github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/par/queue.go (about)

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package par
     6  
     7  // Queue manages a set of work items to be executed in parallel. The number of
     8  // active work items is limited, and excess items are queued sequentially.
     9  type Queue struct {
    10  	maxActive int
    11  	st        chan queueState
    12  }
    13  
    14  // NewQueue returns a Queue that executes up to maxActive items in parallel.
    15  //
    16  // maxActive must be positive.
    17  func NewQueue(maxActive int) *Queue
    18  
    19  // Add adds f as a work item in the queue.
    20  //
    21  // Add returns immediately, but the queue will be marked as non-idle until after
    22  // f (and any subsequently-added work) has completed.
    23  func (q *Queue) Add(f func())
    24  
    25  // Idle returns a channel that will be closed when q has no (active or enqueued)
    26  // work outstanding.
    27  func (q *Queue) Idle() <-chan struct{}