asyncio: demo & test

This commit is contained in:
Li Jie
2024-08-05 20:21:11 +08:00
parent 9102ca6b1e
commit a1d46e905b
3 changed files with 40 additions and 42 deletions

View File

@@ -1,21 +1,26 @@
package main
import "github.com/goplus/llgo/x/async"
import (
"fmt"
"github.com/goplus/llgo/x/async"
)
func GenInts() (co *async.Promise[int]) {
print("1")
println("gen: 1")
co.Yield(1)
print("2")
println("gen: 2")
co.Yield(2)
print("3")
println("gen: 3")
co.Yield(3)
print("4")
return
}
func main() {
co := GenInts()
for !co.Done() {
print(co.Next())
fmt.Printf("got: %v\n", co.Value())
co.Next()
}
fmt.Printf("done\n")
}