Skip to content

Commit 8b34f36

Browse files
committed
rename package
1 parent 596fdc5 commit 8b34f36

File tree

9 files changed

+154
-154
lines changed

9 files changed

+154
-154
lines changed

README.md

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1-
# go-async 🌀
1+
# go-pool 🌀
22

3-
[![CI Status](https://github.com/rubengp99/go-async/actions/workflows/ci.yml/badge.svg)](https://github.com/rubengp99/go-async/actions/workflows/ci.yml)
4-
[![Version](https://img.shields.io/github/v/release/rubengp99/go-async)](https://github.com/rubengp99/go-async/releases)
3+
[![CI Status](https://github.com/rubengp99/go-pool/actions/workflows/ci.yml/badge.svg)](https://github.com/rubengp99/go-pool/actions/workflows/ci.yml)
4+
[![Version](https://img.shields.io/github/v/release/rubengp99/go-pool)](https://github.com/rubengp99/go-pool/releases)
55
![Coverage](https://img.shields.io/badge/Coverage-86.6%25-brightgreen)
6-
[![Go Report Card](https://goreportcard.com/badge/github.com/rubengp99/go-async)](https://goreportcard.com/report/github.com/rubengp99/go-async)
7-
[![GoDoc](https://pkg.go.dev/badge/github.com/rubengp99/go-async)](https://pkg.go.dev/github.com/rubengp99/go-async)
8-
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rubengp99/go-async/blob/dev/LICENSE.md)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/rubengp99/go-pool)](https://goreportcard.com/report/github.com/rubengp99/go-pool)
7+
[![GoDoc](https://pkg.go.dev/badge/github.com/rubengp99/go-pool)](https://pkg.go.dev/github.com/rubengp99/go-pool)
8+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rubengp99/go-pool/blob/dev/LICENSE.md)
99

10-
> A lightweight, type-safe, and retryable asynchronous worker pool for Go — built on **`sync.WaitGroup`**, **semaphores**, **context**, and **condition variables**, _not_ `errgroup`.
10+
> A lightweight, type-safe, and retryable concurrent worker pool for Go — built on **`sync.WaitGroup`**, **semaphores**, **context**, and **condition variables**, _not_ `errgroup`.
1111
12-
`go-async` provides deterministic, leak-free concurrency with automatic retries, result draining, and type-safe tasks, suitable for high-throughput Go applications.
12+
`go-pool` provides deterministic, leak-free concurrency with automatic retries, result draining, and type-safe tasks, suitable for high-throughput Go applications.
1313

1414
---
1515

16-
## Features
16+
## Features
1717

18-
- Type-safe generic workers (`Task[T]`)
19-
- 🧩 Graceful error propagation
20-
- 🔁 Built-in retry with exponential backoff + jitter
21-
- ⚡ Asynchronous result draining (`Drain`)
22-
- 🧵 Deterministic shutdown (no goroutine leaks)
23-
- 🔒 Mutex + condition variable–protected data aggregation
24-
- 🧰 Fluent functional composition (`WithRetry`, `DrainTo`, `WithInput`)
25-
- 🧠 Implemented with `sync.WaitGroup`, semaphores, `context`, and `sync.Cond`
18+
- Type-safe generic workers (`Task[T]`)
19+
- Graceful error propagation
20+
- Built-in retry with exponential backoff + jitter
21+
- Concurrent result draining (`Drain`)
22+
- Deterministic shutdown (no goroutine leaks)
23+
- Mutex + condition variable–protected data aggregation
24+
- Fluent functional composition (`WithRetry`, `DrainTo`, `WithInput`)
25+
- Implemented with `sync.WaitGroup`, semaphores, `context`, and `sync.Cond`
2626

2727
---
2828

29-
## 📦 Installation
29+
## Installation
3030

3131
```bash
32-
go get github.com/rubengp99/go-async
32+
go get github.com/rubengp99/go-pool
3333
```
3434

3535
---
3636

37-
## 🧠 Concept Overview
37+
## Concept Overview
3838

3939
| Type | Description |
4040
|------|-------------|
4141
| `Task[T]` | Represents a unit of async work |
4242
| `Pool` | Manages concurrent execution using WaitGroup and semaphores |
43-
| `Drain[T]` | Collects results asynchronously using mutex + condition variable |
43+
| `Drain[T]` | Collects results concurrently using mutex + condition variable |
4444
| `Args[T]` | Provides task input and drainer reference |
4545
| `Worker` | Interface for executable and retryable tasks |
4646

4747
---
4848

49-
## ⚙️ How It Works
49+
## How It Works
5050

5151
`Pool` orchestrates multiple `Worker`s concurrently:
5252
1. Each worker runs in a separate goroutine managed by a `WaitGroup`.
5353
2. Concurrency is controlled with a semaphore.
5454
3. Shared `context` handles cancellation.
55-
4. `Drain[T]` asynchronously collects results.
55+
4. `Drain[T]` concurrently collects results.
5656
5. On completion, resources and channels close automatically.
5757

5858
---
5959

60-
## 🧩 Example Usage
60+
## Example Usage
6161

6262
### Basic Task
6363

6464
```go
65-
output := async.NewDrainer[User]()
66-
task := async.NewTask(func(t async.Args[User]) error {
65+
output := pool.NewDrainer[User]()
66+
task := pool.NewTask(func(t pool.Args[User]) error {
6767
t.Drainer.Send(User{Name: "Alice"})
6868
return nil
6969
}).DrainTo(output)
7070

71-
pool := async.NewPool()
71+
pool := pool.NewPool()
7272
defer pool.Close()
7373

7474
pool.Go(task).Wait()
@@ -80,37 +80,37 @@ fmt.Println(results[0].Name) // Alice
8080

8181
```go
8282
var numRetries int
83-
task := async.NewTask(func(t async.Args[any]) error {
83+
task := pool.NewTask(func(t pool.Args[any]) error {
8484
numRetries++
8585
if numRetries < 3 {
8686
return fmt.Errorf("transient error")
8787
}
8888
return nil
8989
}).WithRetry(3, 200*time.Millisecond)
9090

91-
pool := async.NewPool()
91+
pool := pool.NewPool()
9292
pool.Go(task).Wait()
9393
```
9494

9595
### Multiple Task Types
9696

9797
```go
98-
outA := async.NewDrainer[A]()
99-
outB := async.NewDrainer[B]()
98+
outA := pool.NewDrainer[A]()
99+
outB := pool.NewDrainer[B]()
100100

101101
// Task A
102-
t1 := async.NewTask(func(t async.Args[A]) error {
102+
t1 := pool.NewTask(func(t pool.Args[A]) error {
103103
t.Drainer.Send(A{Value: "Hello"})
104104
return nil
105105
}).DrainTo(outA)
106106

107107
// Task B
108-
t2 := async.NewTask(func(t async.Args[B]) error {
108+
t2 := pool.NewTask(func(t pool.Args[B]) error {
109109
t.Drainer.Send(B{Value: 42.5})
110110
return nil
111111
}).DrainTo(outB)
112112

113-
pool := async.NewPool()
113+
pool := pool.NewPool()
114114
pool.Go(t1, t2).Wait()
115115

116116
fmt.Println(outA.Drain())
@@ -119,7 +119,7 @@ fmt.Println(outB.Drain())
119119

120120
---
121121

122-
## 🧰 Interfaces
122+
## Interfaces
123123

124124
```go
125125
type Worker interface { Executable; Retryable }
@@ -129,7 +129,7 @@ type Retryable interface { WithRetry(attempts uint, sleep time.Duration) Worker
129129

130130
---
131131

132-
## 🧱 Structs and Functions
132+
## Structs and Functions
133133

134134
### Task[T]
135135
- `Execute()` - run the task
@@ -151,7 +151,7 @@ type Retryable interface { WithRetry(attempts uint, sleep time.Duration) Worker
151151

152152
---
153153

154-
## 🧪 Benchmarks
154+
## Benchmarks
155155

156156
```
157157
goos: linux, goarch: amd64, cpu: 13th Gen Intel i9-13900KS
@@ -163,25 +163,25 @@ goos: linux, goarch: amd64, cpu: 13th Gen Intel i9-13900KS
163163
| ChannelsWithOutputAndErrChannel-32 | 259.9 | 2 | 72 B |
164164
| ChannelsWithWaitGroup-32 | 272.8 | 2 | 80 B |
165165
| MutexWithErrGroup-32 | 270.9 | 2 | 102 B |
166-
| AsyncPackageWithDrainer-32 | 277.5 | 4 | 162 B |
166+
| GoPoolWithDrainer-32 | 277.5 | 4 | 162 B |
167167
| ChannelsWithErrGroup-32 | 279.5 | 2 | 80 B |
168-
| AsyncPackage-32 | 297.4 | 3 | 96 B |
168+
| GoPool-32 | 297.4 | 3 | 96 B |
169169

170170
![Benchmark Comparison](go_async_benchmarks.png)
171171

172-
Even though `go-async` adds a small constant overhead compared to `errgroup` (≈100–130 ns per operation),
172+
Even though `go-pool` adds a small constant overhead compared to `errgroup` (≈100–130 ns per operation),
173173
it provides type safety, retries, automatic draining, and deterministic cleanup — all while staying within ~1.7× of native concurrency performance.
174174

175-
### 🧩 Benchmark Insights
175+
### Benchmark Insights
176176

177-
- `AsyncPackage` and `AsyncPackageWithDrainer` show consistent sub-microsecond operation times.
177+
- `GoPool` and `GoPoolWithDrainer` show consistent sub-microsecond operation times.
178178
- Memory allocations remain extremely low — under 250 B/op even with drainer support.
179179
- The performance delta vs `errgroup` reflects controlled synchronization overhead (mutex + condition variable).
180-
- In practice, `go-async` scales linearly with worker count and maintains predictable latency under load.
180+
- In practice, `go-pool` scales linearly with worker count and maintains predictable latency under load.
181181

182182
---
183183

184-
## Design Highlights
184+
## Design Highlights
185185

186186
- Structured concurrency with `sync.WaitGroup`
187187
- Controlled parallelism via semaphores
@@ -202,20 +202,20 @@ it provides type safety, retries, automatic draining, and deterministic cleanup
202202

203203
### Drainer (Drain)
204204

205-
- Create via `async.NewDrainer[T]()`
205+
- Create via `pool.NewDrainer[T]()`
206206
- Use `Send()` to safely push results
207207
- Collect values using `Drain()`
208208
- Internally guarded by `sync.Mutex` and `sync.Cond`
209209

210210
### Task and Worker Management
211211

212-
- Wrap async functions with `async.NewTask()`
212+
- Wrap async functions with `pool.NewTask()`
213213
- Chain configuration fluently using `.WithRetry()` and `.DrainTo()`
214214
- Provide inputs using `.WithInput()`
215215

216216
### Pool
217217

218-
- Use `async.NewPool()` for controlled concurrency
218+
- Use `pool.NewPool()` for controlled concurrency
219219
- Limit parallelism with `.WithLimit(limit)`
220220
- Apply retry policy globally with `.WithRetry(attempts, sleep)`
221221
- Wait for all tasks to complete using `.Wait()`
@@ -232,9 +232,9 @@ go test -bench . -benchmem -memprofile=mem.prof
232232
```
233233
---
234234

235-
## 💬 Summary
235+
## Summary
236236

237-
`go-async` provides a modern, type-safe, and retryable abstraction over Go’s native synchronization primitives — combining simplicity, determinism, and high throughput.
237+
`go-pool` provides a modern, type-safe, and retryable abstraction over Go’s native synchronization primitives — combining simplicity, determinism, and high throughput.
238238

239239
Built for developers who want concurrency that’s:
240240

@@ -245,6 +245,6 @@ Built for developers who want concurrency that’s:
245245

246246
---
247247

248-
## 📜 License
248+
## License
249249

250250
MIT License © 2025 [rubengp99](https://github.com/rubengp99)

benchmark_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package async_test
1+
package gopool_test
22

33
import (
44
"os"
55
"sync"
66
"testing"
77

8-
"github.com/rubengp99/go-async"
8+
gopool "github.com/rubengp99/go-pool"
99
"golang.org/x/sync/errgroup"
1010
)
1111

@@ -24,12 +24,12 @@ func BenchmarkAsyncPackage(b *testing.B) {
2424
//disable internal limit on test
2525
os.Setenv("STAGE", "prod")
2626
// Create a Drain channel for async operations
27-
d := async.NewPool()
27+
d := gopool.NewPool()
2828
defer d.Close()
2929

3030
b.Run("AsyncPackage", func(b *testing.B) {
3131
for i := 0; i < b.N; i++ {
32-
d.Go(async.NewTask(func(arg async.Args[int]) error {
32+
d.Go(gopool.NewTask(func(arg gopool.Args[int]) error {
3333
return SimulatedTask()
3434
}))
3535
}
@@ -45,14 +45,14 @@ func BenchmarkAsyncPackage(b *testing.B) {
4545
func BenchmarkAsyncPackageWithDrainer(b *testing.B) {
4646
//disable internal limit on test
4747
os.Setenv("STAGE", "prod")
48-
d := async.NewPool()
48+
d := gopool.NewPool()
4949
defer d.Close()
5050

5151
b.Run("AsyncPackage", func(b *testing.B) {
52-
o := async.NewDrainer[int]()
52+
o := gopool.NewDrainer[int]()
5353
// Create a Drain channel for async operations
5454
for i := 0; i < b.N; i++ {
55-
d.Go(async.NewTask(func(arg async.Args[int]) error {
55+
d.Go(gopool.NewTask(func(arg gopool.Args[int]) error {
5656
i := i
5757
arg.Drainer.Send(i)
5858
return SimulatedTask()

drain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package async
1+
package gopool
22

33
import (
44
"sync"

drain_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package async_test
1+
package gopool_test
22

33
import (
44
"testing"
55

6-
"github.com/rubengp99/go-async"
6+
gopool "github.com/rubengp99/go-pool"
77
"github.com/stretchr/testify/assert"
88
)
99

1010
func TestDrainer(t *testing.T) {
1111

12-
drainer := async.NewDrainer[typeA]()
12+
drainer := gopool.NewDrainer[typeA]()
1313
drainer.Send(typeA{value: "1"})
1414
drainer.Send(typeA{value: "2"})
1515
drainer.Send(typeA{value: "3"})

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/rubengp99/go-async
1+
module github.com/rubengp99/go-pool
22

33
go 1.25.0
44

pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package async
1+
package gopool
22

33
import (
44
"context"

0 commit comments

Comments
 (0)