Package dispatcher implements a customizable Job Queue Dispatcher.
This package is a simple Job Queue of the Dispatcher-Worker model.
Implemented with API design that emphasizes Dispatcher's ease of creation and behavior customization.
- Simple Job-Queue
- Custom Dispatcher behavior
Please install Package and include it in code.
package main
import "github.com/kamiazya/go-dispatcher"
You can get Dispatcher whth some Options like this.
// New Dispatcher
d, err := dispatcher.New(
dispatcher.MaxWorker(2),
dispatcher.MaxRetry(2),
)
if err != nil {
// do something.
}
d.Start()
d.Dispatch(func() error {
// do something.
return nil
})
// wait for all tasks done
d.Wait()
You can get Dispatcher whth Config like this.
// default config
c := dispatcher.DafaultConfig()
// set value to config
c.MaxQueue = 10
// generate Dispatcher from config
d, _ := dispatcher.GenerateFromConfig(*c)
d.Start()
d.Dispatch(func() error {
// do something.
fmt.Println("this is the pettern of ")
return nil
})
// Stop Dispatcher after all tasks done.
d.Stop(false)
go get github.com/kamiazya/go-dispatcher