优化写法

This commit is contained in:
shijian 2023-12-18 09:30:57 +08:00
parent 8cbc92d5bb
commit d84208747a
1 changed files with 9 additions and 4 deletions

View File

@ -32141,9 +32141,6 @@ new Promise(resolve=>{
// 事件结束后触发resolve
event.resolve=resolve;
if(!_status.event) return;
if(!game.executingAsyncEventMap){
game.executingAsyncEventMap=new Map();
}
// game.createEvent的时候还没立即push到next里
Promise.resolve().then(()=>{
game.executingAsyncEventMap.set(_status.event.toEvent(),(game.executingAsyncEventMap.get(_status.event.toEvent())||Promise.resolve()).then(()=>{
@ -41446,6 +41443,14 @@ new Promise(resolve=>{
setTimeout(game.reload,15000)
}
},
/**
* @type { Map<GameEvent, Promise<any>> }
*
* 以Promise储存异步事件的执行链使async content调用事件时无需必须使用await
*
* 但是需要事件结果的除外
*/
executingAsyncEventMap:new Map(),
/**
* @param { Promise<GameEvent> & GameEvent & GameEventPromise } [belongAsyncEvent]
*/
@ -41644,7 +41649,7 @@ new Promise(resolve=>{
else if (event.content instanceof AsyncFunction) {
// _status,lib,game,ui,get,ai六个变量由game.import提供
event.content(event, trigger, player).then(() => {
if (game.executingAsyncEventMap && game.executingAsyncEventMap.has(event.toEvent())) {
if (game.executingAsyncEventMap.has(event.toEvent())) {
game.executingAsyncEventMap.set(_status.event.toEvent(), game.executingAsyncEventMap.get(_status.event.toEvent()).then(() => {
event.finish();
resolve();