lib.onload支持传入GeneratorFunction以解决需要异步函数的问题
This commit is contained in:
parent
78b0a78217
commit
bcaf584bfe
44
game/game.js
44
game/game.js
|
@ -29,6 +29,36 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){
|
||||
try{
|
||||
var info=gen[key](arg);
|
||||
var value=info.value;
|
||||
}catch(error){
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if(info.done){
|
||||
resolve(value);
|
||||
}else{
|
||||
Promise.resolve(value).then(_next,_throw);
|
||||
}
|
||||
}
|
||||
function _asyncToGenerator(fn){
|
||||
return function(){
|
||||
var self=this,args=arguments;
|
||||
return new Promise(function(resolve, reject){
|
||||
var gen=fn.apply(self,args);
|
||||
function _next(value){
|
||||
asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);
|
||||
}
|
||||
function _throw(err){
|
||||
asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);
|
||||
}
|
||||
_next(undefined);
|
||||
});
|
||||
};
|
||||
}
|
||||
const GeneratorFunction=(function*(){}).constructor;
|
||||
const _status={
|
||||
paused:false,
|
||||
paused2:false,
|
||||
|
@ -8791,11 +8821,17 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
onload:function(){
|
||||
//lib.onload支持传入GeneratorFunction以解决异步函数的问题 by诗笺
|
||||
onload:_asyncToGenerator(function*(){
|
||||
const libOnload=lib.onload;
|
||||
delete lib.onload;
|
||||
while(libOnload.length){
|
||||
libOnload.shift()();
|
||||
while(Array.isArray(libOnload)&&libOnload.length){
|
||||
const fun=libOnload.shift();
|
||||
if(fun instanceof GeneratorFunction){
|
||||
yield _asyncToGenerator(fun)();
|
||||
}else{
|
||||
fun();
|
||||
}
|
||||
}
|
||||
ui.updated();
|
||||
game.documentZoom=game.deviceZoom;
|
||||
|
@ -9554,7 +9590,7 @@
|
|||
}
|
||||
localStorage.removeItem(lib.configprefix+'directstart');
|
||||
delete lib.init.init;
|
||||
},
|
||||
}),
|
||||
startOnline:function(){
|
||||
'step 0'
|
||||
event._resultid=null;
|
||||
|
|
Loading…
Reference in New Issue