Skip to content

Commit

Permalink
BrokerDispatcher.RunAllTubes() fires immediately.
Browse files Browse the repository at this point in the history
Previously it would wait 10 seconds before finding tubes to watch.
  • Loading branch information
pda committed May 7, 2014
1 parent 39162e3 commit dea156f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions broker/broker_dispatcher.go
@@ -1,6 +1,7 @@
package broker

import (
"log"
"time"

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

go func() {
ticker := time.Tick(ListTubeDelay)
ticker := instantTicker(ListTubeDelay)
for _ = range ticker {
if e := bd.watchNewTubes(); e != nil {
// ignore error
log.Println(e)
}
}
}()
Expand Down Expand Up @@ -92,3 +93,16 @@ func (bd *BrokerDispatcher) watchNewTubes() (err error) {

return
}

// Like time.Tick() but also fires immediately.
func instantTicker(t time.Duration) <-chan time.Time {
c := make(chan time.Time)
ticker := time.NewTicker(t)
go func() {
c <- time.Now()
for t := range ticker.C {
c <- t
}
}()
return c
}

0 comments on commit dea156f

Please sign in to comment.