Documentation
¶
Overview ¶
Example ¶
f, counter := New(), 0
showLevel := func() {
counter++
fmt.Println("level", counter)
}
// Next starts a new level, and put the job `showLevel` in it
f.Next(showLevel)
for i := 0; i < 20; i++ {
v := i
// With add func in this level
f.With(func() {
// do some stuff
fmt.Println(v)
})
}
// start a new level
f.Next(showLevel)
for i := 0; i < 20; i++ {
v := i
f.With(func() {
// do some stuff
fmt.Println(v)
})
}
// limit the number of concurrent jobs
f.SetLimit(10)
// wait and add counter
f.Run()
Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 level 1 level 2
Index ¶
- Variables
- func SetGlobalPoolSize(size int) error
- type ErrorHandler
- type Flow
- func (f *Flow) Next(jobs ...func()) *Flow
- func (f *Flow) OnPanic(panicHandler func(interface{})) *Flow
- func (f *Flow) Run()
- func (f *Flow) SetErrorHandler(h ErrorHandler) *Flow
- func (f *Flow) SetGroutinePool(p GroutinePool) *Flow
- func (f *Flow) SetLimit(limit int) *Flow
- func (f *Flow) With(jobs ...func()) *Flow
- type GroutinePool
- type PanicHandler
- type Runner
- type RunnerOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidRunner = errors.New("invalid runner")
)
View Source
var Silent = false
Silent disable all error message
Functions ¶
func SetGlobalPoolSize ¶
SetGlobalPoolSize sets global ants pool size (must be called before any task runs)
Types ¶
type ErrorHandler ¶
type ErrorHandler func(error)
type Flow ¶
type Flow struct {
// contains filtered or unexported fields
}
Flow is a sync model
func NewWithLimit ¶
func NewWithPool ¶
func NewWithPool(p GroutinePool) *Flow
func (*Flow) Next ¶
Next add funcs in next level Next: wait level1(run f1, run f2, run f3...) ... wait level2(...)... (in order)
func (*Flow) SetErrorHandler ¶
func (f *Flow) SetErrorHandler(h ErrorHandler) *Flow
func (*Flow) SetGroutinePool ¶
func (f *Flow) SetGroutinePool(p GroutinePool) *Flow
type GroutinePool ¶
type GroutinePool interface {
Submit(func()) error
}
type PanicHandler ¶
type PanicHandler func(interface{})
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func NewRunner ¶
func NewRunner(p GroutinePool, ro ...RunnerOptions) *Runner
func NewRunnerWithAntsPool ¶
func NewRunnerWithAntsPool(size int, ro ...RunnerOptions) (*Runner, error)
type RunnerOptions ¶
type RunnerOptions func(*Runner)
func WithPanicHandler ¶
func WithPanicHandler(ph PanicHandler) RunnerOptions
Click to show internal directories.
Click to hide internal directories.