2020-09-21 09:49:33 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
// WorkerPool represents the tool for control
|
|
|
|
// the execution of go-routine pool.
|
|
|
|
type WorkerPool interface {
|
|
|
|
// Submit queues a function for execution
|
|
|
|
// in a separate routine.
|
|
|
|
//
|
|
|
|
// Implementation must return any error encountered
|
|
|
|
// that prevented the function from being queued.
|
|
|
|
Submit(func()) error
|
|
|
|
}
|
|
|
|
|
2021-10-08 13:29:52 +00:00
|
|
|
// PseudoWorkerPool represents pseudo worker pool which executes submitted job immediately in the caller's routine..
|
|
|
|
type PseudoWorkerPool struct{}
|
2020-09-21 09:49:33 +00:00
|
|
|
|
|
|
|
// Submit executes passed function immediately.
|
|
|
|
//
|
|
|
|
// Always returns nil.
|
2021-10-08 13:29:52 +00:00
|
|
|
func (PseudoWorkerPool) Submit(fn func()) error {
|
2020-09-21 09:49:33 +00:00
|
|
|
fn()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|