Skip to content

Commit 504d4e0

Browse files
committed
docs: fix indent
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 60ec169 commit 504d4e0

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

README.md

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,81 +42,81 @@ func (j *job) Bytes() []byte {
4242
The second step to create the new worker, use the buffered channel as an example, you can use the `stop` channel to terminate the job immediately after shutdown the queue service if need.
4343

4444
```go
45-
// define the worker
46-
w := simple.NewWorker(
47-
simple.WithQueueNum(taskN),
48-
simple.WithRunFunc(func(m queue.QueuedMessage, stop <-chan struct{}) error {
49-
v, ok := m.(*job)
50-
if !ok {
51-
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
52-
return err
53-
}
45+
// define the worker
46+
w := simple.NewWorker(
47+
simple.WithQueueNum(taskN),
48+
simple.WithRunFunc(func(m queue.QueuedMessage, stop <-chan struct{}) error {
49+
v, ok := m.(*job)
50+
if !ok {
51+
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
52+
return err
5453
}
54+
}
5555

56-
rets <- v.Message
57-
return nil
58-
}),
59-
)
56+
rets <- v.Message
57+
return nil
58+
}),
59+
)
6060
```
6161

6262
or use the [NSQ](https://nsq.io/) as backend, see the worker example:
6363

6464
```go
65-
// define the worker
66-
w := nsq.NewWorker(
67-
nsq.WithAddr("127.0.0.1:4150"),
68-
nsq.WithTopic("example"),
69-
nsq.WithChannel("foobar"),
70-
// concurrent job number
71-
nsq.WithMaxInFlight(10),
72-
nsq.WithRunFunc(func(m queue.QueuedMessage, stop <-chan struct{}) error {
73-
v, ok := m.(*job)
74-
if !ok {
75-
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
76-
return err
77-
}
65+
// define the worker
66+
w := nsq.NewWorker(
67+
nsq.WithAddr("127.0.0.1:4150"),
68+
nsq.WithTopic("example"),
69+
nsq.WithChannel("foobar"),
70+
// concurrent job number
71+
nsq.WithMaxInFlight(10),
72+
nsq.WithRunFunc(func(m queue.QueuedMessage, stop <-chan struct{}) error {
73+
v, ok := m.(*job)
74+
if !ok {
75+
if err := json.Unmarshal(m.Bytes(), &v); err != nil {
76+
return err
7877
}
78+
}
7979

80-
rets <- v.Message
81-
return nil
82-
}),
83-
)
80+
rets <- v.Message
81+
return nil
82+
}),
83+
)
8484
```
8585

8686
The third step to create a queue and initialize multiple workers, receive all job messages:
8787

8888
```go
89-
// define the queue
90-
q, err := queue.NewQueue(
91-
queue.WithWorkerCount(5),
92-
queue.WithWorker(w),
93-
)
94-
if err != nil {
95-
log.Fatal(err)
96-
}
89+
// define the queue
90+
q, err := queue.NewQueue(
91+
queue.WithWorkerCount(5),
92+
queue.WithWorker(w),
93+
)
94+
if err != nil {
95+
log.Fatal(err)
96+
}
9797

98-
// start the five worker
99-
q.Start()
98+
// start the five worker
99+
q.Start()
100100

101-
// assign tasks in queue
102-
for i := 0; i < taskN; i++ {
103-
go func(i int) {
104-
q.Queue(&job{
105-
Message: fmt.Sprintf("handle the job: %d", i+1),
106-
})
107-
}(i)
108-
}
101+
// assign tasks in queue
102+
for i := 0; i < taskN; i++ {
103+
go func(i int) {
104+
q.Queue(&job{
105+
Message: fmt.Sprintf("handle the job: %d", i+1),
106+
})
107+
}(i)
108+
}
109109

110-
// wait until all tasks done
111-
for i := 0; i < taskN; i++ {
112-
fmt.Println("message:", <-rets)
113-
time.Sleep(50 * time.Millisecond)
114-
}
110+
// wait until all tasks done
111+
for i := 0; i < taskN; i++ {
112+
fmt.Println("message:", <-rets)
113+
time.Sleep(50 * time.Millisecond)
114+
}
115115

116-
// shutdown the service and notify all the worker
117-
q.Shutdown()
118-
// wait all jobs are complete.
119-
q.Wait()
116+
// shutdown the service and notify all the worker
117+
q.Shutdown()
118+
// wait all jobs are complete.
119+
q.Wait()
120120
```
121121

122122
Full example code as below or [try it in playground](https://play.golang.org/p/yaTUoYxdcaK).

0 commit comments

Comments
 (0)