2023-10-09 17:36:04 +08:00
|
|
|
|
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("测试执行")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 请求功能测试
|
2023-10-12 14:04:23 +08:00
|
|
|
|
resultFuture := ecs.Request[int](sim, func() ecs.Result[int] {
|
2023-10-09 17:36:04 +08:00
|
|
|
|
fmt.Println("执行请求")
|
2023-10-12 14:04:23 +08:00
|
|
|
|
return ecs.NewOkResult[int](20)
|
2023-10-09 17:36:04 +08:00
|
|
|
|
})
|
2023-10-12 14:04:23 +08:00
|
|
|
|
result := <-resultFuture
|
2023-10-09 17:36:04 +08:00
|
|
|
|
fmt.Println("执行结果:", result)
|
|
|
|
|
|
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
}
|