Skip to content

f2prateek/go-executor

Repository files navigation

go-executor

Experimental executor implementation for Go.

Decouples task submission from mechanics of how each task will be run.

Currently provides a single implemention via the PoolExecutor.

In this example, the pooled executor will guarantee that only upto 20 goroutines run at a given time.

func main() {
    e := NewPooledExecutor(20)

    var wg sync.WaitGroup
    for i := 0; i < 100; i++ {
        wg.Add(1)
        e.enqueue(func() {
            defer wg.Done()
            time.Sleep(500 * time.Millisecond)
            fmt.Println("hello")
        })
    }

    wg.Wait()
}

Easy to see that in tests you could swap the executor for a simpler implementation, such as a syncronous executor.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published