Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 541 Bytes

README.md

File metadata and controls

26 lines (21 loc) · 541 Bytes

Cirque

A circular queue that processes jobs in parallel but returns results in FIFO.

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]