Skip to content

Commit 0140653

Browse files
committed
docs: update example
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 6e2c98e commit 0140653

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ q.Start()
128128
for i := 0; i < taskN; i++ {
129129
go func(i int) {
130130
q.Queue(&job{
131+
Name: "foobar",
131132
Message: fmt.Sprintf("handle the job: %d", i+1),
132133
})
133134
}(i)
@@ -151,6 +152,7 @@ Full example code as below or [try it in playground](https://play.golang.org/p/y
151152
package main
152153

153154
import (
155+
"context"
154156
"encoding/json"
155157
"fmt"
156158
"log"
@@ -161,11 +163,16 @@ import (
161163
)
162164

163165
type job struct {
166+
Name string
164167
Message string
165168
}
166169

167170
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
169176
}
170177

171178
func main() {
@@ -175,15 +182,15 @@ func main() {
175182
// define the worker
176183
w := simple.NewWorker(
177184
simple.WithQueueNum(taskN),
178-
simple.WithRunFunc(func(m queue.QueuedMessage, _ <-chan struct{}) error {
185+
simple.WithRunFunc(func(ctx context.Context, m queue.QueuedMessage) error {
179186
v, ok := m.(*job)
180187
if !ok {
181188
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
182189
return err
183190
}
184191
}
185192

186-
rets <- v.Message
193+
rets <- "Hi, " + v.Name + ", " + v.Message
187194
return nil
188195
}),
189196
)
@@ -204,6 +211,7 @@ func main() {
204211
for i := 0; i < taskN; i++ {
205212
go func(i int) {
206213
q.Queue(&job{
214+
Name: "foobar",
207215
Message: fmt.Sprintf("handle the job: %d", i+1),
208216
})
209217
}(i)

0 commit comments

Comments
 (0)