cl: compile async functions
This commit is contained in:
37
cl/_testdata/async/in.go
Normal file
37
cl/_testdata/async/in.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package async_compile
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goplus/llgo/x/async"
|
||||
)
|
||||
|
||||
func GenInts() (co *async.Promise[int]) {
|
||||
co.Yield(1)
|
||||
co.Yield(2)
|
||||
co.Yield(3)
|
||||
return
|
||||
}
|
||||
|
||||
func WrapGenInts() *async.Promise[int] {
|
||||
return GenInts()
|
||||
}
|
||||
|
||||
func UseGenInts() int {
|
||||
co := WrapGenInts()
|
||||
r := 0
|
||||
for !co.Done() {
|
||||
r += co.Next()
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func GenIntsWithDefer() (co *async.Promise[int]) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println("panic:", r)
|
||||
}
|
||||
}()
|
||||
co.Yield(1)
|
||||
panic("GenIntsWithDefer")
|
||||
}
|
||||
Reference in New Issue
Block a user