mirror of
https://github.com/appium/appium.git
synced 2026-02-09 19:28:48 -06:00
Using Async.queue to queue commands
This commit is contained in:
@@ -42,8 +42,7 @@ Android.prototype.init = function () {
|
||||
this.args.devicePort = 4724;
|
||||
this.appMd5Hash = null;
|
||||
this.args.avd = null;
|
||||
this.queue = [];
|
||||
this.progress = 0;
|
||||
this.initQueue();
|
||||
this.implicitWaitMs = 0;
|
||||
this.shuttingDown = false;
|
||||
this.adb = null;
|
||||
@@ -89,7 +88,6 @@ Android.prototype.start = function (cb, onDie) {
|
||||
this.uiautomator.setExitHandler(this.onUiautomatorExit.bind(this));
|
||||
|
||||
logger.debug("Using fast reset? " + this.args.fastReset);
|
||||
|
||||
async.series([
|
||||
this.prepareDevice.bind(this),
|
||||
this.packageAndLaunchActivityFromManifest.bind(this),
|
||||
@@ -387,8 +385,6 @@ Android.prototype.stop = function (cb) {
|
||||
|
||||
Android.prototype.cleanup = function () {
|
||||
logger.info("Cleaning up android objects");
|
||||
this.queue = [];
|
||||
this.progress = 0;
|
||||
this.adb = null;
|
||||
this.uiautomator = null;
|
||||
this.shuttingDown = false;
|
||||
@@ -422,43 +418,19 @@ Android.prototype.shutdown = function (cb) {
|
||||
Android.prototype.proxy = deviceCommon.proxy;
|
||||
Android.prototype.respond = deviceCommon.respond;
|
||||
|
||||
Android.prototype.push = function (elem) {
|
||||
this.queue.push(elem);
|
||||
|
||||
var next = function () {
|
||||
if (this.queue.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.queue[0] === null) {
|
||||
this.queue.shift();
|
||||
return;
|
||||
}
|
||||
|
||||
// Always send the command.
|
||||
if (this.progress > 0) {
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
var target = this.queue.shift()
|
||||
, action = target[0][0]
|
||||
, params = typeof target[0][1] === "undefined" ? {} : target[0][1]
|
||||
, cb = target[1];
|
||||
Android.prototype.initQueue = function () {
|
||||
this.queue = async.queue(function (task, cb) {
|
||||
var action = task.action,
|
||||
params = task.params;
|
||||
|
||||
this.cbForCurrentCmd = cb;
|
||||
|
||||
this.progress++;
|
||||
|
||||
if (this.adb && !this.shuttingDown) {
|
||||
this.uiautomator.sendAction(action, params, function (response) {
|
||||
this.cbForCurrentCmd = null;
|
||||
if (typeof cb === 'function') {
|
||||
this.respond(response, cb);
|
||||
}
|
||||
|
||||
// maybe there's moar work to do
|
||||
this.progress--;
|
||||
next();
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.cbForCurrentCmd = null;
|
||||
@@ -468,17 +440,16 @@ Android.prototype.push = function (elem) {
|
||||
msg = "We're in the middle of shutting down the Android device, " +
|
||||
"so your request won't be executed. Sorry!";
|
||||
}
|
||||
|
||||
this.respond({
|
||||
status: status.codes.UnknownError.code
|
||||
, value: msg
|
||||
}, cb);
|
||||
this.progress--;
|
||||
next();
|
||||
}
|
||||
}.bind(this);
|
||||
}
|
||||
}.bind(this), 1);
|
||||
};
|
||||
|
||||
next();
|
||||
Android.prototype.push = function (elem) {
|
||||
this.queue.push({action:elem[0][0], params:elem[0][1] || {}}, elem[1]);
|
||||
};
|
||||
|
||||
Android.prototype.wakeUp = function (cb) {
|
||||
|
||||
Reference in New Issue
Block a user