Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arxdsilva/async
https://github.com/arxdsilva/async
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/arxdsilva/async
- Owner: arxdsilva
- Created: 2023-02-27T12:18:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-02-27T13:24:01.000Z (over 1 year ago)
- Last Synced: 2024-10-12T09:20:06.317Z (about 1 month ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# async
Simple golang worker sync pool that matches your best number of goroutines with the available CPUs. This optimizes the number of go routines so that you always have the best performance.
This lib does:
1. create go routines according to your number of available CPUs;
2. sync the work to be done by them;
3. stop work with the given context;## Why
1. Managing worker loads is repetitive work;
2. Worker code always leads to managing go routines;
3. This provides a standard way of doing that in a efficient manner;
4. Less code for you to manage;
5. No external dependencies;## How to use
1. Start your app
2. Define your work function
3. Setup the `async` lib
4. Send data to be worked on your function
5. Manage your errors### Full example
```go
import (
"github.com/arxdsilva/async"
)func main() {
... // 1. start your app
workFn := myFunction // 2.define your work functiondataChan, errChan := async.New(
ctx, workFn,
async.WithChanSizeData(1000),
async.WithChanSizeErr(2)) // 3. setup the async libmw := myWorker{
DC: dataChan, // 4. Setup your worker to send data to the async execution
EC: errChan, // 5. Setup your worker to manage generated errors
}mw.Start()
}
```