修复async content中事件不使用await会报错的问题
This commit is contained in:
parent
7cade08dd9
commit
d6941b3774
14
game/game.js
14
game/game.js
|
@ -32143,10 +32143,11 @@ new Promise(resolve=>{
|
|||
if(!_status.event) return;
|
||||
// game.createEvent的时候还没立即push到next里
|
||||
Promise.resolve().then(()=>{
|
||||
const eventPromise=_status.event.next.find(e=>e.toEvent()==event);
|
||||
const callback=()=>{
|
||||
let eventPromise=_status.event.next.find(e=>e.toEvent()==event);
|
||||
// 如果父级事件也是一个异步的话,那应该立即执行这个事件的
|
||||
// 如果在AsyncFunction执行过程中在别的位置新建了一个异步事件,那也直接(等会set配置完)执行
|
||||
if(eventPromise&&_status.event.content instanceof AsyncFunction){
|
||||
if (eventPromise&&_status.event.content instanceof AsyncFunction){
|
||||
if(_status.event!=eventPromise){
|
||||
eventPromise.parent=_status.event;
|
||||
_status.event=eventPromise;
|
||||
|
@ -32156,8 +32157,15 @@ new Promise(resolve=>{
|
|||
// 不直接game.loop(event)是因为需要让别人可以手动set()和setContent()
|
||||
// 再执行game.loop是因为原有的game.loop被await卡住了,
|
||||
// 得新执行一个只执行这个异步事件的game.loop
|
||||
Promise.resolve().then(()=>game.loop(eventPromise));
|
||||
game.executingAsyncEvent=Promise.resolve().then(()=>game.loop(eventPromise))
|
||||
.then(()=>{
|
||||
delete game.executingAsyncEvent;
|
||||
});
|
||||
}
|
||||
};
|
||||
// 没有await上个事件(也就是_status.event)
|
||||
if(game.executingAsyncEvent) game.executingAsyncEvent.then(callback);
|
||||
else callback();
|
||||
});
|
||||
});
|
||||
this.#event=event;
|
||||
|
|
Loading…
Reference in New Issue