* ast: improve error handling * ast: handle select * dyngo: set filename of executed script * cfg: improve error reporting * Implement select for receiving channels * feat(select): add support for sending channels in case clauses * test: improve tests on select * feat(select): add support for "default" case
32 lines
436 B
Go
32 lines
436 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func main() {
|
|
c1 := make(chan string)
|
|
c2 := make(chan string)
|
|
|
|
go func() {
|
|
toSend := "hello"
|
|
select {
|
|
case c2 <- toSend:
|
|
fmt.Println("Sent", toSend, "to c2")
|
|
}
|
|
}()
|
|
|
|
select {
|
|
case msg1 := <-c1:
|
|
fmt.Println("received from c1:", msg1)
|
|
case msg2 := <-c2:
|
|
fmt.Println("received from c2:", msg2)
|
|
}
|
|
fmt.Println("Bye")
|
|
}
|
|
|
|
// Output:
|
|
// Sent hello to c2
|
|
// received from c2: hello
|
|
// Bye
|