Skip to content
/ pool Public

This library/module provides goroutine pool executor with the completion wait support

License

Notifications You must be signed in to change notification settings

fblaha/pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pool

GoDoc Build Status Sourcegraph

This library/module provides goroutine pool executor with the completion wait support. An executor that executes each submitted job using one of possibly several pooled goroutines.

Download

go get github.com/fblaha/pool

Usage

An user has 2 options how to implement jobs:

  1. By type implementing Worker interface (executor.Submit)
type Worker interface {
	Work()
}
  1. By pure function (executor.SubmitFunc)
type WorkerFunc func()

Simple Example

// creates a new executor with a pool of 10 goroutines
executor := NewExecutor(10)

// terminates worker go routines and frees allocated resources
defer executor.ShutdownGracefully()

// submits 2 worker functions simulating time consuming jobs
executor.SubmitFunc(
    func() {
        time.Sleep(100 * time.Millisecond)
        fmt.Println("hard work done")
    },
    func() {
        time.Sleep(200 * time.Millisecond)
        fmt.Println("double hard work done")

    })

// waits for the completion of above submitted work
// the wait call influences the order of the output lines
executor.Wait()

// submits a one more worker function simulating a short time job
executor.SubmitFunc(
    func() {
        // this line should occur in the output last due to above wait call
        fmt.Println("easy work done")
    })

// Output:
//hard work done
//double hard work done
//easy work done

Real Example

About

This library/module provides goroutine pool executor with the completion wait support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages