Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yuchanns/all
all: A Parallelism tool for Go
https://github.com/yuchanns/all
Last synced: about 1 month ago
JSON representation
all: A Parallelism tool for Go
- Host: GitHub
- URL: https://github.com/yuchanns/all
- Owner: yuchanns
- License: apache-2.0
- Created: 2024-11-13T10:30:30.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-13T10:50:56.000Z (about 2 months ago)
- Last Synced: 2024-11-13T11:31:20.746Z (about 2 months ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 🚀 all: A Parallelism Tool for Go
[![Go Reference](https://pkg.go.dev/badge/go.yuchanns.xyz/all.svg)](https://pkg.go.dev/go.yuchanns.xyz/all) ![Behavior Test](https://github.com/yuchanns/all/actions/workflows/behavior_test.yaml/badge.svg?branch=main)
**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.
### 📦 Installation
```bash
go get go.yuchanns.xyz/all
```### 🔧 Usage
1. Basic Usage:
```go
package mainimport (
"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()
}
```2. Collect the results in a slice following the input order:
```go
results, err := all.Collect(x)
```3. By default, the executor stops when any error occurs. You can change this behavior:
```go
all.Persist(x)
```### 📜 License
[Apache License 2.0](LICENSE)