var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.waitForEmulator=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _ora=_interopRequireDefault(require("ora"));
var _exec=require("../../systemManager/exec");

var waitForEmulator=function waitForEmulator(c,cli,command,callback){var attempts,maxAttempts,CHECK_INTEVAL,maxErrorLength,spinner;return _regenerator.default.async(function waitForEmulator$(_context){while(1){switch(_context.prev=_context.next){case 0:
attempts=0;
maxAttempts=30;
CHECK_INTEVAL=2000;
maxErrorLength=c.program.maxErrorLength;
spinner=(0,_ora.default)('Waiting for emulator to boot...').start();return _context.abrupt("return",

new Promise(function(resolve,reject){
var interval=setInterval(function(){
(0,_exec.execCLI)(c,cli,command,{
silent:true,
timeout:10000,
maxErrorLength:maxErrorLength}).

then(function(resp){
if(callback(resp)){
clearInterval(interval);
spinner.succeed();
return resolve(true);
}
attempts++;
if(attempts===maxAttempts){
clearInterval(interval);
spinner.fail(
"Can't connect to the running emulator. Try restarting it.");

return reject(
"Can't connect to the running emulator. Try restarting it.");

}
}).
catch(function(){
attempts++;
if(attempts>maxAttempts){
clearInterval(interval);
spinner.fail(
"Can't connect to the running emulator. Try restarting it.");

return reject(
"Can't connect to the running emulator. Try restarting it.");

}
});
},CHECK_INTEVAL);
}));case 6:case"end":return _context.stop();}}},null,null,null,Promise);};exports.waitForEmulator=waitForEmulator;
//# sourceMappingURL=common.js.map