Commit 25b02b0a authored by Boris Mühmer's avatar Boris Mühmer
Browse files

added some basic concurrency examples (and empty skeletons)

parent cd8c7a09
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
package concurrency
+79 −0
Original line number Diff line number Diff line
package concurrency

import "testing"

func TestConcurrencyBasic001(t *testing.T) {
	stringStream := make(chan string)
	close(stringStream)
	go func() {
		stringStream <- "Hello from goroutine!"
	}()

	salutation, ok := <-stringStream
	t.Logf("status \"%t\": \"%s\"", ok, salutation)

	salutation, ok = <-stringStream
	t.Logf("status \"%t\": \"%s\"", ok, salutation)
}

func TestConcurrencyBasic002(t *testing.T) {
	stringStream := make(chan string)
	defer close(stringStream)
	go func() {
		stringStream <- "Hello from goroutine!"
	}()

	salutation, ok := <-stringStream
	t.Logf("status \"%t\": \"%s\"", ok, salutation)

	salutation, ok = <-stringStream
	t.Logf("status \"%t\": \"%s\"", ok, salutation)
}

func TestConcurrencyBasic003(t *testing.T) {
	stringStream := make(chan string)
	go func() {
		defer close(stringStream)
		stringStream <- "Hello from goroutine!"
	}()

	salutation, ok := <-stringStream
	t.Logf("status \"%t\": \"%s\"", ok, salutation)

	salutation, ok = <-stringStream
	t.Logf("status \"%t\": \"%s\"", ok, salutation)
}
func TestConcurrencyBasic004(t *testing.T) {
	intStream := make(chan int)
	go func() {
		defer close(intStream)
		for i := 0; i < 10; i++ {
			intStream <- i
		}
	}()

	for j := range intStream {
		t.Logf("j: %d", j)
	}
}
func TestConcurrencyBasic005(t *testing.T) {

}
func TestConcurrencyBasic006(t *testing.T) {

}
func TestConcurrencyBasic007(t *testing.T) {

}
func TestConcurrencyBasic008(t *testing.T) {

}
func TestConcurrencyBasic009(t *testing.T) {

}
func TestConcurrencyBasic010(t *testing.T) {

}
func TestConcurrencyBasic011(t *testing.T) {

}