modify names.

This commit is contained in:
Rintim 2023-09-06 00:53:11 +08:00
parent 92504b1adf
commit f99ec24852
1 changed files with 8 additions and 6 deletions

View File

@ -32,17 +32,18 @@
const GeneratorFunction=(function*(){}).constructor; const GeneratorFunction=(function*(){}).constructor;
// gnc: GeNCoroutine // gnc: GeNCoroutine
const gnc={ const gnc={
async:(fn)=>function genCoroutine(){ async:fn=>function genCoroutine(){
return gnc.await(fn.apply(this,arguments)) return gnc.await(fn.apply(this,arguments))
}, },
await:(gen)=>new Promise((resolve,reject)=>{ await:gen=>new Promise((resolve,reject)=>{
const _next=value=>gnc.next(gen,resolve,reject,"next",value,_next,_throw); const _next=value=>gnc.next(gen,resolve,reject,"next",value,_next,_throw);
const _throw=err=>gnc.next(gen,resolve,reject,"throw",err,_next,_throw); const _throw=err=>gnc.next(gen,resolve,reject,"throw",err,_next,_throw);
_next(undefined); _next(undefined);
}), }),
is:{ is:{
coroutine:(item)=>typeof item=="function"&&item.name=="genCoroutine", coroutine:item=>typeof item=="function"&&item.name=="genCoroutine",
generator:(item)=>item instanceof GeneratorFunction generator:item=>item instanceof GeneratorFunction,
a:item=>item.constructor==GeneratorFunction
}, },
next:(gen,resolve,reject,key,arg,_next,_throw)=>{ next:(gen,resolve,reject,key,arg,_next,_throw)=>{
let info,value; let info,value;
@ -7157,8 +7158,9 @@
}, },
genAsync:fn=>gnc.async(fn), genAsync:fn=>gnc.async(fn),
genAwait:gen=>gnc.await(gen), genAwait:gen=>gnc.await(gen),
isGenCoroutine:(item)=>typeof item=="function"&&item.name=="genCoroutine", isGenCoroutine:item=>gnc.is.coroutine(item),
isGenerator:(item)=>item instanceof GeneratorFunction, isGeneratorFunc:item=>gnc.is.generator(item),
isGenerator:item=>gnc.is.a(item),
init:{ init:{
init:function(){ init:function(){
if(typeof __dirname==='string'&&__dirname.length){ if(typeof __dirname==='string'&&__dirname.length){