https://github.com/kitstack/async-job
AsyncJob is an asynchronous queue job manager with light code, clear and speed. I hope so ! 😬
https://github.com/kitstack/async-job
async lightweight queue simple
Last synced: 2 months ago
JSON representation
AsyncJob is an asynchronous queue job manager with light code, clear and speed. I hope so ! 😬
- Host: GitHub
- URL: https://github.com/kitstack/async-job
- Owner: kitstack
- License: mit
- Created: 2022-02-12T12:49:26.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-30T18:51:58.000Z (about 4 years ago)
- Last Synced: 2025-09-26T11:13:00.400Z (9 months ago)
- Topics: async, lightweight, queue, simple
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/lab210-dev/async-job/actions/workflows/go.yml)

[](https://goreportcard.com/report/github.com/lab210-dev/async-job)
[](https://codecov.io/gh/lab210-dev/async-job)
[](https://github.com/lab210-dev/async-job/blob/main/LICENSE)
# Overview
AsyncJob is an asynchronous job manager with light code, clear and speed. I hope so ! 😬
## Features
- [x] AsyncJob is a simple asynchronous job manager.
- [x] Full code coverage
- [x] Async queue
- [x] Define the number of asynchronous tasks (default: runtime.NumCPU())
- [x] Handling of managed and unmanaged errors
- [x] Provide a simple ETA
- [x] Full code description
### Usage
```go
package main
import (
"github.com/lab210-dev/async-job"
"log"
)
func main() {
// Create a new AsyncJob
asj := asyncjob.New[string]()
// Set the number of asynchronous tasks (default: runtime.NumCPU())
asj.SetWorkers(2)
// Listen to the progress status
asj.OnProgress(func(progress asyncjob.Progress) {
log.Printf("Progress: %s\n", progress.String())
})
// Run all jobs
err := asj.Run(func(job asyncjob.Job[string]) error {
// receive the job in job data function
// if err return or panic, the job will be marked as failed and all progress will be canceled
return nil
}, []string{"Hello", "World"})
// if a job returns an error, it stops the process
if err != nil {
log.Fatal(err)
}
}
```
## 💡 For better performance
Using a modulo to reduce the eta display (fast example)
```go
package main
import (
"github.com/lab210-dev/async-job"
"log"
"time"
)
func main() {
// create slice of jobs
var list []time.Duration
for i := 1; i <= 100; i++ {
list = append(list, time.Duration(1)*time.Millisecond)
}
err := asyncjob.New[time.Duration]().
SetWorkers(2).
OnProgress(func(progress asyncjob.Progress) {
// Eta will be displayed every 10 jobs
if progress.Current()%10 != 0 {
return
}
// print the eta
log.Printf("Progress: %s\n", progress.String())
}).
Run(func(job asyncjob.Job[time.Duration]) error {
// slow down the job
time.Sleep(job.Data())
return nil
}, list)
// if a job returns an error, it stops the process
if err != nil {
log.Fatal(err)
}
}
```
## 🤝 Contributions
Contributors to the package are encouraged to help improve the code.