Skip to content

Commit

Permalink
DRY up On function
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Dec 18, 2013
1 parent 2c83fb3 commit 6f01605
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ func Rand(max int) int {
return rand.Intn(max)
}

func On(cs chan interface{}) interface{} {
for s := range cs {
return s
}
return nil
func On(cs chan interface{}, f func(s interface{})) {
go func() {
for s := range cs {
f(s)
}
}()
}

func ConnectToTcp(port string) io.ReadWriteCloser {
Expand Down

0 comments on commit 6f01605

Please sign in to comment.