mirror of
https://github.com/fhmq/hmq.git
synced 2026-05-04 07:08:32 +00:00
29 lines
427 B
Go
29 lines
427 B
Go
package broker
|
|
|
|
import "sync"
|
|
|
|
type Work struct {
|
|
WorkerPool *sync.Pool
|
|
Message *Message
|
|
}
|
|
|
|
type Worker struct {
|
|
WorkerChannel chan Work
|
|
}
|
|
|
|
func NewWorker() Worker {
|
|
w := Worker{WorkerChannel: make(chan Work)}
|
|
return w.Start()
|
|
}
|
|
|
|
func (w Worker) Start() Worker {
|
|
go func() {
|
|
for work := range w.WorkerChannel {
|
|
ProcessMessage(work.Message)
|
|
// put the worker back
|
|
work.WorkerPool.Put(w)
|
|
}
|
|
}()
|
|
return w
|
|
}
|