mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 02:57:46 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
e4fc3bb66a
commit
bbc3046687
Vendored
+18
-1
@@ -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() {
|
||||
|
||||
Vendored
+2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user