1
0
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:
Wei Fu 2017-03-30 21:21:58 +08:00
parent abba91a6ac
commit c1b89ad941
2 changed files with 16 additions and 14 deletions

View File

@ -15,7 +15,7 @@ const (
TimeoutDial = 5 * time.Second
TimeoutShutdown = 5 * time.Second
ProcessDuration = 2 * time.Second
ProcessDuration = 3 * time.Second
)
var (

View File

@ -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
}