Skip to content

Gaziri (газыри́) — tiny lib for goroutine pooling and throttling

License

Notifications You must be signed in to change notification settings

hypersolid/gaziri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gaziri

Build Status Go Report Card

About

It's a tiny DRY lib for goroutine pooling and throttling.

  1. Provide a worker function that takes interface{} as input and returns interface{} as output.
  2. Set your limits on number of running tasks per second maxWorkersPerSecond and task in general maxWorkers.
  3. Shoot your tasks int Input channel and listen to Output.

Quickstart

pool := gaziri.NewPool(
  func(value interface{}) interface{} {
    // works goes here
    time.Sleep(2 * time.Second)
    return value.(int) * 2
  },
  100, //  max workers
  30,  //  max rps
)

go func() {
  for i := 0; i < jobs; i++ {
    pool.Input <- i // enqueue tasks
  }
}()

for i := 0; i < jobs; i++ {
  <-pool.Output // get results
}

About

Gaziri (газыри́) — tiny lib for goroutine pooling and throttling

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages