Skip to content

Commit dea156f

Browse files
committed
BrokerDispatcher.RunAllTubes() fires immediately.
Previously it would wait 10 seconds before finding tubes to watch.
1 parent 39162e3 commit dea156f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

broker/broker_dispatcher.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package broker
22

33
import (
4+
"log"
45
"time"
56

67
"github.com/kr/beanstalk"
@@ -60,10 +61,10 @@ func (bd *BrokerDispatcher) RunAllTubes() (err error) {
6061
}
6162

6263
go func() {
63-
ticker := time.Tick(ListTubeDelay)
64+
ticker := instantTicker(ListTubeDelay)
6465
for _ = range ticker {
6566
if e := bd.watchNewTubes(); e != nil {
66-
// ignore error
67+
log.Println(e)
6768
}
6869
}
6970
}()
@@ -92,3 +93,16 @@ func (bd *BrokerDispatcher) watchNewTubes() (err error) {
9293

9394
return
9495
}
96+
97+
// Like time.Tick() but also fires immediately.
98+
func instantTicker(t time.Duration) <-chan time.Time {
99+
c := make(chan time.Time)
100+
ticker := time.NewTicker(t)
101+
go func() {
102+
c <- time.Now()
103+
for t := range ticker.C {
104+
c <- t
105+
}
106+
}()
107+
return c
108+
}

0 commit comments

Comments
 (0)