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

16 lines
277 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 ecs
// 请求世界执行给定函数
func Request[T any](w World, fn func() T) chan T {
future := make(chan T)
w.Execute(func() {
r := fn()
select {
// 及时外面不接收也不会卡停World运行
case future <- r:
default:
}
})
return future
}