mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
all: implement trivial select statements
Implement two trivial uses of the select statement.
Always blocking:
select {}
No-op:
select {
default:
}
Go 1.12 added a `select {}` instruction to syscall/js, so this is needed
for Go 1.12 support. More complete support for select will be added in
the future.
This commit is contained in:
committed by
Ron Evans
parent
4d82f42d61
commit
ad7297a539
Vendored
+18
@@ -43,6 +43,10 @@ func main() {
|
||||
}
|
||||
println("sum(100):", sum)
|
||||
|
||||
// Test select
|
||||
go selectDeadlock()
|
||||
go selectNoOp()
|
||||
|
||||
// Allow goroutines to exit.
|
||||
time.Sleep(time.Microsecond)
|
||||
}
|
||||
@@ -93,3 +97,17 @@ func iterator(ch chan int, top int) {
|
||||
}
|
||||
close(ch)
|
||||
}
|
||||
|
||||
func selectDeadlock() {
|
||||
println("deadlocking")
|
||||
select {}
|
||||
println("unreachable")
|
||||
}
|
||||
|
||||
func selectNoOp() {
|
||||
println("select no-op")
|
||||
select {
|
||||
default:
|
||||
}
|
||||
println("after no-op")
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -19,3 +19,6 @@ sum: 25
|
||||
sum: 29
|
||||
sum: 33
|
||||
sum(100): 4950
|
||||
deadlocking
|
||||
select no-op
|
||||
after no-op
|
||||
|
||||
Reference in New Issue
Block a user