Skip to content

Commit 506077f

Browse files
committed
docs: update example
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent b950ca6 commit 506077f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ Third to create queue and initialize multiple worker, receive all job message:
109109
q.Wait()
110110
```
111111

112-
Full example code as below or [try it in playground](https://play.golang.org/p/DlhCQgZZ1Bb).
112+
Full example code as below or [try it in playground](https://play.golang.org/p/xuR4WhcFdoQ).
113113

114114
```go
115115
package main
116116

117117
import (
118-
"errors"
118+
"encoding/json"
119119
"fmt"
120120
"log"
121121
"time"
@@ -125,11 +125,11 @@ import (
125125
)
126126

127127
type job struct {
128-
message string
128+
Message string
129129
}
130130

131131
func (j *job) Bytes() []byte {
132-
return []byte(j.message)
132+
return []byte(j.Message)
133133
}
134134

135135
func main() {
@@ -140,12 +140,14 @@ func main() {
140140
w := simple.NewWorker(
141141
simple.WithQueueNum(taskN),
142142
simple.WithRunFunc(func(m queue.QueuedMessage) error {
143-
j, ok := m.(*job)
143+
v, ok := m.(*job)
144144
if !ok {
145-
return errors.New("message is not job type")
145+
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
146+
return err
147+
}
146148
}
147149

148-
rets <- j.message
150+
rets <- v.Message
149151
return nil
150152
}),
151153
)
@@ -166,7 +168,7 @@ func main() {
166168
for i := 0; i < taskN; i++ {
167169
go func(i int) {
168170
q.Queue(&job{
169-
message: fmt.Sprintf("handle the job: %d", i+1),
171+
Message: fmt.Sprintf("handle the job: %d", i+1),
170172
})
171173
}(i)
172174
}

0 commit comments

Comments
 (0)