-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
50 lines (39 loc) · 1.34 KB
/
generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package eventdemo
import (
"sync"
"time"
)
// Generator ...
type Generator struct {
waitGroup *sync.WaitGroup
}
// NewGenerator ...
func NewGenerator(waitGroup *sync.WaitGroup) Generator {
return Generator{waitGroup}
}
// GenerateMessages ...
func (g *Generator) GenerateMessages(messages chan Message) {
defer close(messages)
for _, message := range produceMessages() {
messages <- message
time.Sleep(10 * time.Millisecond) // simulate hard work
}
g.waitGroup.Done()
}
func produceMessages() []Message {
messages := []Message{}
messages = append(messages, NewMessage("Hello Gophers", Hello))
messages = append(messages, NewMessage("Hello Stuttgart", Hello))
messages = append(messages, NewMessage("First steps in go", Ping))
messages = append(messages, NewMessage("Next steps in go", Ping))
messages = append(messages, NewMessage("I am still listening", Ping))
messages = append(messages, NewMessage(`{ "content-type": "json" }`, Ping))
messages = append(messages, NewMessage("Can't wait to try it out myself", Ping))
messages = append(messages, NewMessage("Super excited to hear the next talk", Ping))
messages = append(messages, NewMessage("Thanks for coming", Goodbye))
messages = append(messages, NewMessage("Good night Stuttgart", Goodbye))
for i := 0; i < 100; i++ {
messages = append(messages, messages[i%10])
}
return messages
}