mirror of
https://github.com/oarkflow/mq.git
synced 2025-10-05 16:06:55 +08:00
31 lines
602 B
Go
31 lines
602 B
Go
package mq
|
|
|
|
import (
|
|
"github.com/oarkflow/xsync"
|
|
)
|
|
|
|
type Queue struct {
|
|
name string
|
|
consumers xsync.IMap[string, *consumer]
|
|
tasks chan *QueuedTask // channel to hold tasks
|
|
}
|
|
|
|
func newQueue(name string, queueSize int) *Queue {
|
|
return &Queue{
|
|
name: name,
|
|
consumers: xsync.NewMap[string, *consumer](),
|
|
tasks: make(chan *QueuedTask, queueSize), // buffer size for tasks
|
|
}
|
|
}
|
|
|
|
func (b *Broker) NewQueue(qName string) *Queue {
|
|
q, ok := b.queues.Get(qName)
|
|
if ok {
|
|
return q
|
|
}
|
|
q = newQueue(qName, b.opts.queueSize)
|
|
b.queues.Set(qName, q)
|
|
go b.dispatchWorker(q)
|
|
return q
|
|
}
|