new future IO and demo

This commit is contained in:
Li Jie
2024-09-05 16:00:26 +08:00
parent 6e0a9b2b48
commit a2d4e79c20
14 changed files with 706 additions and 507 deletions

View File

@@ -1,6 +1,3 @@
//go:build llgo
// +build llgo
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
@@ -27,16 +24,16 @@ import (
"github.com/goplus/llgo/x/cbind"
)
func Timeout(d time.Duration) async.IO[async.Void] {
func Timeout(d time.Duration) async.Future[async.Void] {
return async.Async(func(resolve func(async.Void)) {
t, _ := cbind.BindF[libuv.Timer, libuv.TimerCb](func() {
t, cb := cbind.BindF[libuv.Timer, libuv.TimerCb](func(t *libuv.Timer) {
resolve(async.Void{})
})
r := libuv.InitTimer(async.Exec().L, t)
if r != 0 {
panic("InitTimer failed")
}
r = t.Start(cbind.Callback[libuv.Timer], uint64(d/time.Millisecond), 0)
r = t.Start(cb, uint64(d/time.Millisecond), 0)
if r != 0 {
panic("Start failed")
}