concurrency

This commit is contained in:
Steven Degutis
2012-03-17 12:04:10 -05:00
parent cb6c0229c1
commit 95e2dcf25d
3 changed files with 38 additions and 4 deletions

31
about_concurrency.go Normal file
View File

@@ -0,0 +1,31 @@
package go_koans
func isPrimeNumber(possiblePrime int) bool {
for underPrime := 2; underPrime < possiblePrime; underPrime++ {
if possiblePrime % underPrime == 0 {
return false
}
}
return true
}
func findPrimeNumbers(channel chan int) {
for i := 2; /* infinite loop */ ; i++ {
// your code goes here
assert(i < 100) // i is afraid of heights
}
}
func aboutConcurrency() {
ch := make(chan int)
assert(__delete_me__) // concurrency can be almost trivial
// your code goes here
assert(<-ch == 2)
assert(<-ch == 3)
assert(<-ch == 5)
assert(<-ch == 7)
assert(<-ch == 11)
}

5
about_panics.go Normal file
View File

@@ -0,0 +1,5 @@
package go_koans
func aboutPanics() {
panic("crap")
}

View File

@@ -15,6 +15,7 @@ var __int__ int = -1
var __byte__ byte = 255
var __bool__ bool = false // ugh
var __float32__ float32 = -1.0
var __delete_me__ bool = false
func TestKoans(t *testing.T) {
aboutNumbers()
@@ -31,10 +32,7 @@ func TestKoans(t *testing.T) {
aboutPointers()
aboutStructs()
aboutAllocation()
// TODO: ie, gameplan
//aboutGoroutines()
//aboutChannels()
aboutConcurrency()
//aboutPanics()
fmt.Printf("\n%c[32;1mYou won life. Good job.\n\n", 27)