forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template1.go
55 lines (41 loc) · 1.43 KB
/
template1.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
51
52
53
54
55
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// http://play.golang.org/p/G7O-DnJrEA
// Write a program where two goroutines pass an integer back and forth
// ten times. Display when each goroutine receives the integer. Increment
// the integer with each pass. Once the integer equals ten, terminate
// the program cleanly.
package main
// Add imports.
// Declare a wait group variable.
// Declare a function for the goroutine. Pass in a name for the
// routine and a channel of type int used to share the value back and forth.
func goroutine( /* parameters */ ) {
for {
// Receive on the channel, waiting for the integer.
// Check if the channel is closed.
{
// Call done on the waitgroup.
// Display the goroutine is finished and return.
}
// Display the integer value received.
// Check is the value from the channel is 10.
{
// Close the channel.
// Call done on the waitgroup.
// Display the goroutine is finished and return.
}
// Increment the value by one and send in back through
// the channel.
}
}
// main is the entry point for all Go programs.
func main() {
// Declare and initialize an unbuffered channel
// of type int.
// Increment the wait group for each goroutine
// to be created.
// Create the two goroutines.
// Send the initial integer value into the channel.
// Wait for all the goroutines to finish.
}