Skip to content

A nice pool worker that allows you as a developer to configure the pool size and the number of workers. Also having 2 dispatcher types (async/sync) and have the control over the go routine

License

Notifications You must be signed in to change notification settings

tomiok/splanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPLANNER


A really nice pool worker


Config

  • In your main file or something like that
// init the shared data structure.
splanner.InitQueue(20)

// init the dispatcher & keep it listening.
splanner.NewDispatcher(15).Run(true)
  • The caller should have something similar...
type HeavyWork struct {
    Name   string
    number int
}

// implement the job method, and heavyWork is now implementing the Unit interface
func (p *HeavyWork) Job() error {
    time.Sleep(500 * time.Millisecond)
    fmt.Println(fmt.Sprintf("heavy job is running %d", p.number))
    return nil
}

work := HeavyWork{Name: q, number: a}
// add the work here, could be in a loop to add more than one or whatever you want
splanner.AddUnit(&work)

About

A nice pool worker that allows you as a developer to configure the pool size and the number of workers. Also having 2 dispatcher types (async/sync) and have the control over the go routine

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages