compiler: add support for async interface calls

This commit is contained in:
Jaden Weiss
2019-11-17 10:53:26 -05:00
committed by Ayke van Laethem
parent 81199da3f1
commit 98eee7c22a
6 changed files with 62 additions and 15 deletions
+40
View File
@@ -1,5 +1,7 @@
package main
import "time"
func main() {
thing := &Thing{"foo"}
println("thing:", thing.String())
@@ -87,6 +89,14 @@ func main() {
println("test", i, "of interfaceEqualTests failed")
}
}
// test interface blocking
blockDynamic(NonBlocker{})
println("non-blocking call on sometimes-blocking interface")
blockDynamic(SleepBlocker(time.Millisecond))
println("slept 1ms")
blockStatic(SleepBlocker(time.Millisecond))
println("slept 1ms")
}
func printItf(val interface{}) {
@@ -134,6 +144,14 @@ func nestedSwitch(verb rune, arg interface{}) bool {
return false
}
func blockDynamic(blocker DynamicBlocker) {
blocker.Block()
}
func blockStatic(blocker StaticBlocker) {
blocker.Sleep()
}
type Thing struct {
name string
}
@@ -211,3 +229,25 @@ type Unmatched interface {
type linkedList struct {
addr *linkedList
}
type DynamicBlocker interface {
Block()
}
type NonBlocker struct{}
func (b NonBlocker) Block() {}
type SleepBlocker time.Duration
func (s SleepBlocker) Block() {
time.Sleep(time.Duration(s))
}
func (s SleepBlocker) Sleep() {
s.Block()
}
type StaticBlocker interface {
Sleep()
}
+3
View File
@@ -19,3 +19,6 @@ SmallPair.Print: 3 5
Stringer.String(): foo
Stringer.(*Thing).String(): foo
nested switch: true
non-blocking call on sometimes-blocking interface
slept 1ms
slept 1ms