jl-ecs/examples/main.go
walker 37e06d2aaf 添加Result类型
修改请求处理接口
2023-10-12 14:04:23 +08:00

37 lines
589 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"time"
"joylink.club/ecs"
)
func main() {
sim := ecs.NewWorld(20)
sim.StartUp()
sim.Pause()
go func() {
time.Sleep(1 * time.Second)
sim.Resume()
}()
// 超出channel缓冲区超出后会阻塞
for i := 0; i < 50; i++ {
sim.Execute(func() {
fmt.Println("测试执行")
})
}
// 请求功能测试
resultFuture := ecs.Request[int](sim, func() ecs.Result[int] {
fmt.Println("执行请求")
return ecs.NewOkResult[int](20)
})
result := <-resultFuture
fmt.Println("执行结果:", result)
time.Sleep(2 * time.Second)
}