From f8b7941a16e9a63d3e16d6af1c2adfad64454a66 Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 17 Sep 2023 02:53:28 +0800 Subject: [PATCH] logic parse. Originally `gnc.await` would call `gnc.await` internally, so now merging the contents of `gnc.await` into `gnc.async` will definitely cause issues. We will continue to change the `await` logic in `gnc.async` into a callback function, but at this point we only care about the outermost Promise. After the inner Promise finishes handling the asynchronous data, we no longer create nested Promise objects, we just call the callback function again. This also avoids potential performance losses from multi-layered Promises. --- game/game.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/game/game.js b/game/game.js index 6351d1d18..b443c48af 100644 --- a/game/game.js +++ b/game/game.js @@ -36,10 +36,10 @@ let gen=fn.apply(this,arguments); gen.status="next"; gen.state=undefined; - return new Promise((resolve,reject)=>{ - let result=gen; - let nexts=resolve; - let throws=reject; + const callback=(resolve,reject)=>{ + let result, + nexts=resolve, + throws=reject; try{ result=gen[gen.status](gen.state); }catch(error){ @@ -50,17 +50,18 @@ nexts=(item)=>{ gen.state=item; gen.status="next"; - gnc.await(gen).then(resolve,reject); + callback(resolve,reject); } throws=(err)=>{ gen.state=err; gen.status="throw"; - gnc.await(gen).then(resolve,reject); + callback(resolve,reject); } } result=result.value; Promise.resolve(result).then(nexts,throws); - }); + } + return new Promise(callback); }:(()=>{throw new TypeError("gnc.of needs a GeneratorFunction.")})(), /* await:gen=>new Promise((resolve,reject)=>{