jl-ecs/examples/main.go
2023-10-09 17:36:04 +08:00

37 lines
543 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("测试执行")
})
}
// 请求功能测试
future := ecs.Request[int](sim, func() int {
fmt.Println("执行请求")
return 20
})
result := <-future
fmt.Println("执行结果:", result)
time.Sleep(2 * time.Second)
}