github.com/MeteorsLiu/simpleMQ@v1.0.3/queue/queue.go (about) 1 package queue 2 3 import "fmt" 4 5 var ( 6 ErrQueueClosed = fmt.Errorf("queue is closed") 7 ) 8 9 func WithSimpleQueueCap(cap int) Options { 10 return func(queue Queue) { 11 queue.Resize(cap) 12 } 13 } 14 15 type Queue interface { 16 IsClosed() bool 17 Publish(Task) bool 18 ForcePublish(Task) error 19 Subscribe() (chan Task, error) 20 Close() 21 TryPop() (Task, bool) 22 Pop() (Task, error) 23 Resize(int) bool 24 Cap() int 25 Len() int 26 Free() int 27 Copy() []Task 28 // Save() acts like Copy() 29 // but it only allows to call once. 30 Save(func(Task)) 31 } 32 33 type Options func(queue Queue) 34 type NewQueue func(...Options) Queue