sudhirj / cirque

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

Home Page:https://godoc.org/github.com/sudhirj/cirque

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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]

About

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

https://godoc.org/github.com/sudhirj/cirque

License:MIT License


Languages

Language:Go 100.0%