Skip to content

Commit 3e2e4b4

Browse files
committed
chore: add single example
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 622fdd3 commit 3e2e4b4

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed
File renamed without changes.
File renamed without changes.

_example/main.go renamed to _example/single/main.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ func main() {
3333
nats.WithSubj("example"),
3434
nats.WithQueue("foobar"),
3535
nats.WithRunFunc(func(ctx context.Context, m queue.QueuedMessage) error {
36-
v, ok := m.(*job)
37-
if !ok {
38-
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
39-
return err
40-
}
36+
var v *job
37+
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
38+
return err
4139
}
42-
4340
rets <- v.Message
4441
return nil
4542
}),
@@ -60,9 +57,11 @@ func main() {
6057
// assign tasks in queue
6158
for i := 0; i < taskN; i++ {
6259
go func(i int) {
63-
q.Queue(&job{
60+
if err := q.Queue(&job{
6461
Message: fmt.Sprintf("handle the job: %d", i+1),
65-
})
62+
}); err != nil {
63+
log.Fatal(err)
64+
}
6665
}(i)
6766
}
6867

@@ -73,7 +72,5 @@ func main() {
7372
}
7473

7574
// shutdown the service and notify all the worker
76-
q.Shutdown()
77-
// wait all jobs are complete.
78-
q.Wait()
75+
q.Release()
7976
}

0 commit comments

Comments
 (0)