mirror of
https://github.com/tmrts/go-patterns.git
synced 2024-11-29 00:25:31 +03:00
Producer Consumer Part
Like serverAccpet, create routine for consumer if there is available consumer.
This commit is contained in:
parent
abba91a6ac
commit
c1b89ad941
@ -15,7 +15,7 @@ const (
|
||||
TimeoutDial = 5 * time.Second
|
||||
TimeoutShutdown = 5 * time.Second
|
||||
|
||||
ProcessDuration = 2 * time.Second
|
||||
ProcessDuration = 3 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -54,6 +54,7 @@ func (p *Producer) schedule() {
|
||||
// one consumer consumes one job at one time
|
||||
consumer := <-p.consumers
|
||||
|
||||
go func(consumer string) {
|
||||
// if rpcCall fails, this consumer will be regarded as unavailable.
|
||||
err := rpcCall(consumer, "Consumer.DoTask", task, &struct{}{})
|
||||
if err != nil {
|
||||
@ -67,6 +68,7 @@ func (p *Producer) schedule() {
|
||||
}
|
||||
}(consumer)
|
||||
}
|
||||
}(consumer)
|
||||
case <-p.done:
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user