I'm Hanchin Hsieh, a developer passionate about FOSS, and a big Fan of LiSA(織部 里沙). You can ask me about Go, CloudNative, Nvim, and Asahi Linux.
all is a powerful parallelism tool for Go. It offers an easy way to run multiple goroutines concurrently and gather all the results together seamlessly.
go get go.yuchanns.xyz/all
package main
import (
"fmt"
"time"
"go.yuchanns.xyz/all"
)
func consumer(ctx context.Context, input int32) (output string, err error) {
// Process the input
output = fmt.Sprintf("input: %d", input)
return
}
func main() {
// Create a new all executor instance
x := all.New(context.Background(), consumer)
// Assign a task to the executor instance
x.Assign(1)
// Assign another task to the executor instance
x.Assign(2)
// Iterate through the results
for x.Next() {
result := x.Each()
}
// Check for any errors
err := x.Error()
}
results, err := all.Collect(x)
all.Persist(x)
See tests for more examples.