diff options
author | Ayke van Laethem <[email protected]> | 2019-08-15 15:52:26 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-08-17 11:51:43 +0200 |
commit | bbc3046687ffa5bc166cb15a2bc1149192f6f203 (patch) | |
tree | eee541f76066c9b027fd5133ef06842959bb3ae9 /testdata | |
parent | e4fc3bb66a6185f33fce3fcc5128e2996209080b (diff) | |
download | tinygo-bbc3046687ffa5bc166cb15a2bc1149192f6f203.tar.gz tinygo-bbc3046687ffa5bc166cb15a2bc1149192f6f203.zip |
compiler: add support for 'go' on func values
This commit allows starting a new goroutine directly from a func value,
not just when the static callee is known.
This is necessary to support the whole time package, not just the
commonly used subset that was compiled with the SimpleDCE pass enabled.
Diffstat (limited to 'testdata')
-rw-r--r-- | testdata/coroutines.go | 19 | ||||
-rw-r--r-- | testdata/coroutines.txt | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/testdata/coroutines.go b/testdata/coroutines.go index 082e3f63e..47d02598f 100644 --- a/testdata/coroutines.go +++ b/testdata/coroutines.go @@ -28,6 +28,19 @@ func main() { var printer Printer printer = &myPrinter{} printer.Print() + + sleepFuncValue(func(x int) { + time.Sleep(1 * time.Millisecond) + println("slept inside func pointer", x) + }) + time.Sleep(1 * time.Millisecond) + n := 20 + sleepFuncValue(func(x int) { + time.Sleep(1 * time.Millisecond) + println("slept inside closure, with value:", n, x) + }) + + time.Sleep(2 * time.Millisecond) } func sub() { @@ -47,6 +60,10 @@ func delayedValue() int { return 42 } +func sleepFuncValue(fn func(int)) { + go fn(8) +} + func nowait() { println("non-blocking goroutine") } @@ -55,7 +72,7 @@ type Printer interface { Print() } -type myPrinter struct{ +type myPrinter struct { } func (i *myPrinter) Print() { diff --git a/testdata/coroutines.txt b/testdata/coroutines.txt index b4f3c111e..eea625ffd 100644 --- a/testdata/coroutines.txt +++ b/testdata/coroutines.txt @@ -11,3 +11,5 @@ value produced after some time: 42 non-blocking goroutine done with non-blocking goroutine async interface method call +slept inside func pointer 8 +slept inside closure, with value: 20 8 |