You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 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...
typeHeavyWorkstruct {
Namestringnumberint
}
// implement the job method, and heavyWork is now implementing the Unit interfacefunc (p*HeavyWork) Job() error {
time.Sleep(500*time.Millisecond)
fmt.Println(fmt.Sprintf("heavy job is running %d", p.number))
returnnil
}
work:=HeavyWork{Name: q, number: a}
// add the work here, could be in a loop to add more than one or whatever you wantsplanner.AddUnit(&work)