Created
July 18, 2018 13:28
-
-
Save mastern2k3/42e66a7b6c14a3edd950fc218959157b to your computer and use it in GitHub Desktop.
Tester program for a channel and a cosumer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"github.com/satori/go.uuid" | |
) | |
func infiniteUuid(prov chan uuid.UUID) { | |
for { | |
newg := uuid.NewV4() | |
prov <- newg | |
} | |
} | |
func main() { | |
prov := make(chan uuid.UUID) | |
go infiniteUuid(prov) | |
for { | |
count := 0 | |
var data uuid.UUID | |
afterSec := time.After(time.Second) | |
for cont := true; cont; { | |
select { | |
case data = <-prov: | |
count++ | |
case <-afterSec: | |
fmt.Printf("%d msg/s %s was last\n", count, data) | |
cont = false | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment