diff --git a/dummy.go b/dummy.go index 8ae28cb..f1cf96a 100644 --- a/dummy.go +++ b/dummy.go @@ -22,8 +22,8 @@ func (DummyMetrics) QueueLost() {} // It just leaks data to the trash. type DummyDLQ struct{} -func (DummyDLQ) Enqueue(_ interface{}) error { return nil } -func (DummyDLQ) Size() int { return 0 } -func (DummyDLQ) Capacity() int { return 0 } -func (DummyDLQ) Rate() float32 { return 0 } -func (DummyDLQ) Close() error { return nil } +func (DummyDLQ) Enqueue(_ any) error { return nil } +func (DummyDLQ) Size() int { return 0 } +func (DummyDLQ) Capacity() int { return 0 } +func (DummyDLQ) Rate() float32 { return 0 } +func (DummyDLQ) Close() error { return nil } diff --git a/go.mod b/go.mod index dec4eb8..8b132b6 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/koykov/queue -go 1.16 +go 1.18 require github.com/koykov/bitset v1.0.0 diff --git a/interface.go b/interface.go index 6d4ac98..a10f571 100644 --- a/interface.go +++ b/interface.go @@ -3,7 +3,7 @@ package queue // Interface describes queue interface. type Interface interface { // Enqueue puts item to the queue. - Enqueue(x interface{}) error + Enqueue(x any) error // Size return actual size of the queue. Size() int // Capacity return max size of the queue. @@ -17,5 +17,5 @@ type Interface interface { // Worker describes queue worker interface. type Worker interface { // Do process the item. - Do(x interface{}) error + Do(x any) error } diff --git a/logger.go b/logger.go index 02aba24..c27b594 100644 --- a/logger.go +++ b/logger.go @@ -3,7 +3,7 @@ package queue // Logger is an interface of logger interface. // Prints verbose messages. type Logger interface { - Printf(format string, v ...interface{}) - Print(v ...interface{}) - Println(v ...interface{}) + Printf(format string, v ...any) + Print(v ...any) + Println(v ...any) } diff --git a/queue.go b/queue.go index 6adba71..8eb5922 100644 --- a/queue.go +++ b/queue.go @@ -63,7 +63,7 @@ type Queue struct { // item is a wrapper for queue element with retries count. type item struct { - payload interface{} + payload any retries uint32 dexpire int64 // Delayed execution expire time (Unix ns timestamp). } @@ -213,7 +213,7 @@ func (q *Queue) init() { } // Enqueue puts x to the queue. -func (q *Queue) Enqueue(x interface{}) error { +func (q *Queue) Enqueue(x any) error { q.once.Do(q.init) // Check if enqueue is possible. if status := q.getStatus(); status == StatusClose || status == StatusFail { diff --git a/worker/async_chain.go b/worker/async_chain.go index f589ffd..e18232a 100644 --- a/worker/async_chain.go +++ b/worker/async_chain.go @@ -24,16 +24,16 @@ func (w *AsyncChain) Bind(workers ...queue.Worker) *AsyncChain { // Do asynchronously process the item. // Each worker in chain will be called for processing. AsyncChain will stop processing on first failed worker. -func (w AsyncChain) Do(x interface{}) (err error) { +func (w *AsyncChain) Do(x any) (err error) { var ( wg sync.WaitGroup ef uint32 ) - for i := 0; i < len(w); i++ { + for i := 0; i < len(*w); i++ { wg.Add(1) go func(i int) { defer wg.Done() - if err1 := w[i].Do(x); err1 != nil { + if err1 := (*w)[i].Do(x); err1 != nil { if atomic.AddUint32(&ef, 1) == 1 { err = err1 } diff --git a/worker/chain.go b/worker/chain.go index 39c2bf1..5c22278 100644 --- a/worker/chain.go +++ b/worker/chain.go @@ -19,9 +19,9 @@ func (w *Chain) Bind(workers ...queue.Worker) *Chain { // Do process the item. // Each worker in chain will be called for processing. Chain will stop processing on first failed worker. -func (w Chain) Do(x interface{}) (err error) { - for i := 0; i < len(w); i++ { - if err = w[i].Do(x); err != nil { +func (w *Chain) Do(x any) (err error) { + for i := 0; i < len(*w); i++ { + if err = (*w)[i].Do(x); err != nil { return } } diff --git a/worker/transit.go b/worker/transit.go index a4247eb..56a0301 100644 --- a/worker/transit.go +++ b/worker/transit.go @@ -13,7 +13,7 @@ func TransitTo(queue queue.Interface) *Transit { return &w } -func (w Transit) Do(x interface{}) error { +func (w Transit) Do(x any) error { if w.queue == nil { return queue.ErrNoQueue }