concurrency
This commit is contained in:
31
about_concurrency.go
Normal file
31
about_concurrency.go
Normal 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
5
about_panics.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package go_koans
|
||||
|
||||
func aboutPanics() {
|
||||
panic("crap")
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user