2022-08-30 02:30:36 +00:00
|
|
|
package server
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
// TODO: #2 Implement Go routine pool/job queue
|
|
|
|
|
2022-08-30 02:30:36 +00:00
|
|
|
type Worker interface {
|
|
|
|
Add(func())
|
|
|
|
}
|
|
|
|
|
|
|
|
// SimpleWorker is a simple background worker that implements
|
|
|
|
// the Worker interface and runs all tasks in a go routine without
|
|
|
|
// a pool or que or limits. It's useful for simple or small applications
|
|
|
|
// with minimal/short background tasks
|
2023-02-18 06:41:01 +00:00
|
|
|
type SimpleWorker struct{}
|
2022-08-30 02:30:36 +00:00
|
|
|
|
|
|
|
func NewSimpleWorker() *SimpleWorker {
|
|
|
|
return &SimpleWorker{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sw *SimpleWorker) Add(task func()) {
|
|
|
|
go task()
|
|
|
|
}
|