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);
|
let gen=fn.apply(this,arguments);
|
||||||
gen.status="next";
|
gen.status="next";
|
||||||
gen.state=undefined;
|
gen.state=undefined;
|
||||||
return new Promise((resolve,reject)=>{
|
const callback=(resolve,reject)=>{
|
||||||
let result=gen;
|
let result,
|
||||||
let nexts=resolve;
|
nexts=resolve,
|
||||||
let throws=reject;
|
throws=reject;
|
||||||
try{
|
try{
|
||||||
result=gen[gen.status](gen.state);
|
result=gen[gen.status](gen.state);
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
@ -50,17 +50,18 @@
|
||||||
nexts=(item)=>{
|
nexts=(item)=>{
|
||||||
gen.state=item;
|
gen.state=item;
|
||||||
gen.status="next";
|
gen.status="next";
|
||||||
gnc.await(gen).then(resolve,reject);
|
callback(resolve,reject);
|
||||||
}
|
}
|
||||||
throws=(err)=>{
|
throws=(err)=>{
|
||||||
gen.state=err;
|
gen.state=err;
|
||||||
gen.status="throw";
|
gen.status="throw";
|
||||||
gnc.await(gen).then(resolve,reject);
|
callback(resolve,reject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result=result.value;
|
result=result.value;
|
||||||
Promise.resolve(result).then(nexts,throws);
|
Promise.resolve(result).then(nexts,throws);
|
||||||
});
|
}
|
||||||
|
return new Promise(callback);
|
||||||
}:(()=>{throw new TypeError("gnc.of needs a GeneratorFunction.")})(),
|
}:(()=>{throw new TypeError("gnc.of needs a GeneratorFunction.")})(),
|
||||||
/*
|
/*
|
||||||
await:gen=>new Promise((resolve,reject)=>{
|
await:gen=>new Promise((resolve,reject)=>{
|
||||||
|
|
Loading…
Reference in New Issue