Skip to content

Commit

Permalink
[core] Return when Every is sent done on its channel
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed May 14, 2016
1 parent aab1461 commit 0276721
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions examples/every_done.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"fmt"
"time"

"github.com/hybridgroup/gobot"
)

func main() {
gbot := gobot.NewGobot()

robot := gobot.NewRobot(
"hello",
func() {
done := gobot.Every(500*time.Millisecond, func() {
fmt.Println("Greetings human")
})

gobot.After(5*time.Second, func() {
done <- true
fmt.Println("We're done here")
})
},
)

gbot.AddRobot(robot)

gbot.Start()
}
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Every(t time.Duration, f func()) chan bool {
for {
select {
case <-done:
break
return
default:
<-c
go f()
Expand Down
1 change: 1 addition & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestEveryWhenDone(t *testing.T) {
})
<-time.After(20 * time.Millisecond)
done <- true
<-time.After(50 * time.Millisecond)
if i > 1 {
t.Error("Test should have stopped after 20ms")
}
Expand Down

0 comments on commit 0276721

Please sign in to comment.