File tree Expand file tree Collapse file tree 4 files changed +8
-3
lines changed Expand file tree Collapse file tree 4 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ var _ Worker = (*Consumer)(nil)
1313
1414var errMaxCapacity = errors .New ("max capacity reached" )
1515
16- // Worker for simple queue using channel
16+ // Consumer for simple queue using channel
1717type Consumer struct {
1818 taskQueue chan QueuedMessage
1919 runFunc func (context.Context , QueuedMessage ) error
@@ -32,6 +32,7 @@ func (s *Consumer) decBusyWorker() {
3232 s .metric .DecBusyWorker ()
3333}
3434
35+ // BusyWorkers returns the numbers of workers has been busy.
3536func (s * Consumer ) BusyWorkers () uint64 {
3637 return s .metric .BusyWorkers ()
3738}
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ func WithTimeOut(t time.Duration) Option {
6767 }
6868}
6969
70+ // Options for custom args in Queue
7071type Options struct {
7172 workerCount int
7273 timeout time.Duration
@@ -77,6 +78,7 @@ type Options struct {
7778 metric Metric
7879}
7980
81+ // NewOptions initialize the default value for the options
8082func NewOptions (opts ... Option ) * Options {
8183 o := & Options {
8284 workerCount : defaultWorkerCount ,
Original file line number Diff line number Diff line change 11package queue
22
3+ // NewPool initializes a new pool
34func NewPool (size int , opts ... Option ) * Queue {
45 o := []Option {
56 WithWorkerCount (size ),
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ func (j Job) Bytes() []byte {
4747 return j .Payload
4848}
4949
50+ // Encode for encoding the structure
5051func (j Job ) Encode () []byte {
5152 b , _ := json .Marshal (j )
5253 return b
@@ -107,7 +108,7 @@ func (q *Queue) Shutdown() {
107108 })
108109}
109110
110- // Workers returns the numbers of workers has been created .
111+ // Release for graceful shutdown .
111112func (q * Queue ) Release () {
112113 q .Shutdown ()
113114 q .Wait ()
@@ -143,7 +144,7 @@ func (q *Queue) Queue(job QueuedMessage) error {
143144 return q .handleQueue (q .timeout , job )
144145}
145146
146- // Queue to queue all job
147+ // QueueWithTimeout to queue all job with specified timeout.
147148func (q * Queue ) QueueWithTimeout (timeout time.Duration , job QueuedMessage ) error {
148149 return q .handleQueue (timeout , job )
149150}
You can’t perform that action at this time.
0 commit comments