modify `gnc.async` to `gnc.of`.

The name `gnc.async` was originally paired with `gnc.await`, intended to correspond to the `async` and `await` in` JavaScript`. However, having the same name as keywords in the standard library made the meaning of these two functions unclear on our side. The intention of `gnc.async` is to transform generator functions into `genCoroutine`, so it should contain the meaning of "creating". With simple discussion, we decided to use `of` for now to represent "creating" a `genCoroutine`.
This commit is contained in:
Rintim 2023-09-17 02:42:45 +08:00
parent 58379d5835
commit 5893baaf9a
1 changed files with 12 additions and 12 deletions

View File

@ -32,7 +32,7 @@
const GeneratorFunction=(function*(){}).constructor; const GeneratorFunction=(function*(){}).constructor;
// gnc: GeNCoroutine // gnc: GeNCoroutine
const gnc={ const gnc={
async:fn=>function genCoroutine(){ of: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;
@ -7306,10 +7306,10 @@
'无名杀 - 录像 - '+_status.videoToSave.name[0]+' - '+_status.videoToSave.name[1]); '无名杀 - 录像 - '+_status.videoToSave.name[0]+' - '+_status.videoToSave.name[1]);
} }
}, },
genAsync:fn=>gnc.async(fn), genAsync:fn=>gnc.of(fn),
//genAwait:gen=>gnc.await(gen), //genAwait:gen=>gnc.await(gen),
gnc:{ gnc:{
async:fn=>gnc.async(fn), async:fn=>gnc.of(fn),
//await:gen=>gnc.await(gen), //await:gen=>gnc.await(gen),
//escape:gen=>gnc.escape(gen), //escape:gen=>gnc.escape(gen),
is:{ is:{
@ -8363,7 +8363,7 @@
if(!arrayLengths.length) return previousValue+1; if(!arrayLengths.length) return previousValue+1;
return previousValue+Math.min(...arrayLengths); return previousValue+Math.min(...arrayLengths);
},0); },0);
const packLoaded=gnc.async(function*(){ const packLoaded=gnc.of(function*(){
toLoad--; toLoad--;
if(toLoad) return; if(toLoad) return;
if(_status.importing){ if(_status.importing){
@ -8476,13 +8476,13 @@
throw e; throw e;
}); });
var styleToLoad=6; var styleToLoad=6;
var styleLoaded=gnc.async(function*(){ var styleLoaded=gnc.of(function*(){
--styleToLoad; --styleToLoad;
if(styleToLoad==0){ if(styleToLoad==0){
if(extensionlist.length&&(lib.config.mode!='connect'||show_splash)){ if(extensionlist.length&&(lib.config.mode!='connect'||show_splash)){
_status.extensionLoading=[]; _status.extensionLoading=[];
let extToLoad=extensionlist.length; let extToLoad=extensionlist.length;
const extLoaded=gnc.async(function*(){ const extLoaded=gnc.of(function*(){
--extToLoad; --extToLoad;
if(extToLoad==0){ if(extToLoad==0){
yield Promise.allSettled(_status.extensionLoading); yield Promise.allSettled(_status.extensionLoading);
@ -8504,7 +8504,7 @@
continue; continue;
} }
lib.init.js(lib.assetURL+'extension/'+extensionlist[i],'extension',extLoaded,(function(i){ lib.init.js(lib.assetURL+'extension/'+extensionlist[i],'extension',extLoaded,(function(i){
return gnc.async(function*(){ return gnc.of(function*(){
game.removeExtension(i); game.removeExtension(i);
--extToLoad; --extToLoad;
if(extToLoad==0){ if(extToLoad==0){
@ -9152,7 +9152,7 @@
} }
}, },
//lib.onload支持传入GeneratorFunction以解决异步函数的问题 by诗笺 //lib.onload支持传入GeneratorFunction以解决异步函数的问题 by诗笺
onload:gnc.async(function*(){ onload:gnc.of(function*(){
const libOnload=lib.onload; const libOnload=lib.onload;
delete lib.onload; delete lib.onload;
while(Array.isArray(libOnload)&&libOnload.length){ while(Array.isArray(libOnload)&&libOnload.length){
@ -9353,7 +9353,7 @@
}); });
} }
var proceed2=gnc.async(function*(){ var proceed2=gnc.of(function*(){
var mode=lib.imported.mode; var mode=lib.imported.mode;
var card=lib.imported.card; var card=lib.imported.card;
var character=lib.imported.character; var character=lib.imported.character;
@ -9819,7 +9819,7 @@
} }
game.loop(); game.loop();
}) })
var proceed=gnc.async(function*(){ var proceed=gnc.of(function*(){
if(!lib.db){ if(!lib.db){
try{ try{
lib.storage=JSON.parse(localStorage.getItem(lib.configprefix+lib.config.mode)); lib.storage=JSON.parse(localStorage.getItem(lib.configprefix+lib.config.mode));
@ -33677,7 +33677,7 @@
return promise; return promise;
} }
}, },
loadExtension:gnc.async(function*(obj){ loadExtension:gnc.of(function*(obj){
var noeval=false; var noeval=false;
if(typeof obj=='function'){ if(typeof obj=='function'){
obj=yield gnc.await(obj(lib,game,ui,get,ai,_status)); obj=yield gnc.await(obj(lib,game,ui,get,ai,_status));
@ -33852,7 +33852,7 @@
})(); })();
} }
}, },
importExtension:gnc.async(function*(data,finishLoad,exportext,pkg){ importExtension:gnc.of(function*(data,finishLoad,exportext,pkg){
//by 来瓶可乐加冰 //by 来瓶可乐加冰
if(!window.JSZip) if(!window.JSZip)
yield new Promise((resolve,reject)=>lib.init.js(`${lib.assetURL}game`,"jszip",resolve,reject)); yield new Promise((resolve,reject)=>lib.init.js(`${lib.assetURL}game`,"jszip",resolve,reject));