Package goasync is a helper framework for writing asynchronous code in go. It's primary goal is to reduce the amount of boiler plate code one has to write to do concurrent tasks.
Looking for v1, see the master branch
go get -u github.com/brad-jones/goasync/v2/...
package main
import (
"fmt"
"time"
"github.com/brad-jones/goasync/v2/await"
"github.com/brad-jones/goasync/v2/task"
)
func doSomeWorkAsync() *task.Task {
return task.New(func(t *task.Internal) {
time.Sleep(1 * time.Second)
fmt.Println("doing work")
})
}
func main() {
start := time.Now()
fmt.Println("START", start)
task1 := doSomeWorkAsync()
task2 := doSomeWorkAsync()
await.All(task1, task2)
fmt.Println("END", time.Since(start))
}
Running the above will output something similar to:
START 2020-09-11 18:44:14.2406928 +1000 AEST m=+0.003027901
doing work
doing work
END 1.0013651s
Also see further working examples under: https://github.com/brad-jones/goasync/tree/v2/examples