@@ -36,7 +36,11 @@ type job struct {
3636}
3737
3838func (j *job ) Bytes () []byte {
39- return []byte (j.Message )
39+ b , err := json.Marshal (j)
40+ if err != nil {
41+ panic (err)
42+ }
43+ return b
4044}
4145```
4246
@@ -46,7 +50,7 @@ The second step to create the new worker, use the buffered channel as an example
4650// define the worker
4751w := simple.NewWorker (
4852 simple.WithQueueNum (taskN),
49- simple.WithRunFunc (func (m queue. QueuedMessage , stop <- chan struct {} ) error {
53+ simple.WithRunFunc (func (ctx context. Context , m queue. QueuedMessage ) error {
5054 v , ok := m.(*job)
5155 if !ok {
5256 if err := json.Unmarshal (m.Bytes (), &v); err != nil {
@@ -70,7 +74,7 @@ w := nsq.NewWorker(
7074 nsq.WithChannel (" foobar" ),
7175 // concurrent job number
7276 nsq.WithMaxInFlight (10 ),
73- nsq.WithRunFunc (func (m queue. QueuedMessage , stop <- chan struct {} ) error {
77+ nsq.WithRunFunc (func (ctx context. Context , m queue. QueuedMessage ) error {
7478 v , ok := m.(*job)
7579 if !ok {
7680 if err := json.Unmarshal (m.Bytes (), &v); err != nil {
@@ -91,7 +95,7 @@ w := nats.NewWorker(
9195 nats.WithAddr (" 127.0.0.1:4222" ),
9296 nats.WithSubj (" example" ),
9397 nats.WithQueue (" foobar" ),
94- nats.WithRunFunc (func (m queue. QueuedMessage , _ <- chan struct {} ) error {
98+ nats.WithRunFunc (func (ctx context. Context , m queue. QueuedMessage ) error {
9599 v , ok := m.(*job)
96100 if !ok {
97101 if err := json.Unmarshal (m.Bytes (), &v); err != nil {
0 commit comments