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.
This commit is contained in:
parent
31c96dd4ea
commit
f8b7941a16
15
game/game.js
15
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)=>{
|
||||
|
|
Loading…
Reference in New Issue