🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

github.com/dpumford/async

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
a

github.com/dpumford/async

v0.0.3
Version published
Created
Issues
0

Async

This package simplifies the process of running code concurrently. It codifies a common WaitGroup + channels pattern to reduce the amount of code required to start an arbitrary number of concurrent functions and wait for their results. The functions use generics to keep our code honest at compile time.

func main() {
    multiplierQueue := async.NewFunctionQueue[int, int](3)

    for i := 0; i < 10; i++ {
        multiplierQueue.Run(func(num int) (int, error) {
            return num * num, nil
        }, i)
    }

    results := multiplierQueue.Wait()

    for _, v := range results {
        if v.Err != nil {
            panic(v.Err)
        }

        fmt.Println(v.R)
    }
}

A larger example service can be found at ./examples/cat_facts.

FAQs

Package last updated on 05 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts