Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCirque ¶
NewCirque creates a FIFO parallel queue that runs a given processor function on each job, similar to a parallel Map.
The method accepts a parallelism number, which the maximum number of jobs that are processed simultaneously, and a processor function that takes an input and returns an output. The processor function must be safe to call from multiple goroutines.
It returns two channels, one into which inputs can be passed, and one from which outputs can be read. Closing the input channel will close the output channel after processing is complete. Do not close the output channel yourself.
Example ¶
inputs := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} inputChannel, outputChannel := NewCirque(3, func(i int) int { time.Sleep(time.Duration(rand.Int63n(100)) * time.Millisecond) return i * 2 }) go func() { for _, i := range inputs { inputChannel <- i } close(inputChannel) }() var output []int for i := range outputChannel { output = append(output, i) } fmt.Println(output)
Output: [2 4 6 8 10 12 14 16 18 20]
Types ¶
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewSyncMap ¶
func NewSyncMap[K comparable, V any]() *SyncMap[K, V]
Click to show internal directories.
Click to hide internal directories.