determine the arg of `gnc.of` as a generator function.

`gnc.of` needs a generator function, so we check the input value to make the error clear.
This commit is contained in:
Rintim 2023-09-17 02:46:10 +08:00
parent 5893baaf9a
commit 31c96dd4ea
1 changed files with 2 additions and 2 deletions

View File

@ -32,7 +32,7 @@
const GeneratorFunction=(function*(){}).constructor; const GeneratorFunction=(function*(){}).constructor;
// gnc: GeNCoroutine // gnc: GeNCoroutine
const gnc={ const gnc={
of:fn=>function genCoroutine(){ of:fn=>gnc.is.generatorFunc(fn)?function genCoroutine(){
let gen=fn.apply(this,arguments); let gen=fn.apply(this,arguments);
gen.status="next"; gen.status="next";
gen.state=undefined; gen.state=undefined;
@ -61,7 +61,7 @@
result=result.value; result=result.value;
Promise.resolve(result).then(nexts,throws); Promise.resolve(result).then(nexts,throws);
}); });
}, }:(()=>{throw new TypeError("gnc.of needs a GeneratorFunction.")})(),
/* /*
await:gen=>new Promise((resolve,reject)=>{ await:gen=>new Promise((resolve,reject)=>{
let result=gen; let result=gen;