@@ -128,6 +128,7 @@ q.Start()
128
128
for i := 0 ; i < taskN; i++ {
129
129
go func (i int ) {
130
130
q.Queue (&job{
131
+ Name: " foobar" ,
131
132
Message: fmt.Sprintf (" handle the job: %d " , i+1 ),
132
133
})
133
134
}(i)
@@ -151,6 +152,7 @@ Full example code as below or [try it in playground](https://play.golang.org/p/y
151
152
package main
152
153
153
154
import (
155
+ " context"
154
156
" encoding/json"
155
157
" fmt"
156
158
" log"
@@ -161,11 +163,16 @@ import (
161
163
)
162
164
163
165
type job struct {
166
+ Name string
164
167
Message string
165
168
}
166
169
167
170
func (j *job ) Bytes () []byte {
168
- return []byte (j.Message )
171
+ b , err := json.Marshal (j)
172
+ if err != nil {
173
+ panic (err)
174
+ }
175
+ return b
169
176
}
170
177
171
178
func main () {
@@ -175,15 +182,15 @@ func main() {
175
182
// define the worker
176
183
w := simple.NewWorker (
177
184
simple.WithQueueNum (taskN),
178
- simple.WithRunFunc (func (m queue. QueuedMessage , _ <- chan struct {} ) error {
185
+ simple.WithRunFunc (func (ctx context. Context , m queue. QueuedMessage ) error {
179
186
v , ok := m.(*job)
180
187
if !ok {
181
188
if err := json.Unmarshal (m.Bytes (), &v); err != nil {
182
189
return err
183
190
}
184
191
}
185
192
186
- rets <- v.Message
193
+ rets <- " Hi, " + v. Name + " , " + v.Message
187
194
return nil
188
195
}),
189
196
)
@@ -204,6 +211,7 @@ func main() {
204
211
for i := 0 ; i < taskN; i++ {
205
212
go func (i int ) {
206
213
q.Queue (&job{
214
+ Name: " foobar" ,
207
215
Message: fmt.Sprintf (" handle the job: %d " , i+1 ),
208
216
})
209
217
}(i)
0 commit comments