16 lines
277 B
Go
16 lines
277 B
Go
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
|
||
}
|