for function A, the function is to obtain user data asynchronously. Success and fail are officially provided.
now there is a requirement that sometimes function An executes alone without the need to execute function B after successful execution, while function B needs to be executed after fetching user data.
I now set the mark gettingUserData for function A to mark that function An is executing, so for function B, if function An is executing, then there is no need to execute function An again, he just needs to wait for function A to execute successfully and then execute the code that B needs. I don"t know what to do here.
I hope to be able to execute B"s own code immediately after A"s execution is completed. What should I do when I use while (! window.getUserData) {} to find that it doesn"t work?
function A( resolve, reject ){
var self = this
window.gettingUserData = true
sucess:{//
window.getUserData = true
resolve( )
},
fail:{
reject( )
}
}
function B( ){
var callBack = function( ){
//B
}
var p = new Promise( A )
if( window.getUserData ){//B
callBack( )
}else{
if( !window.gettingUserData ){//A
p.then( callBack )
}else{//A
//AA
}
}
}