start the robots in parallel

This commit is contained in:
Adrian Zankich 2014-10-04 00:56:08 -07:00
parent d4ed3117f3
commit b80ad6e167
2 changed files with 15 additions and 12 deletions

View File

@ -75,16 +75,18 @@ Cylon.api = function api() {
//
// Returns nothing
Cylon.start = function start() {
var starters = [];
for (var bot in this.robots) {
this.robots[bot].start();
}
var mode = Utils.fetch(Config, 'workMode', 'async');
if (mode === 'sync') {
console.log('sync');
for (var bot in this.robots) {
this.robots[bot].startWork();
}
starters.push(this.robots[bot].start);
}
Async.parallel(starters, function(err, results) {
var mode = Utils.fetch(Config, 'workMode', 'async');
if (mode === 'sync') {
for (var bot in this.robots) {
this.robots[bot].startWork();
}
}
}.bind(this));
};
// Public: Sets the internal configuration, based on passed options

View File

@ -235,7 +235,7 @@ Robot.prototype.initDevices = function(devices) {
// Starts the connections, devices, and work.
//
// Returns the result of the work
Robot.prototype.start = function() {
Robot.prototype.start = function(callback) {
if (this.running) {
return this;
}
@ -251,7 +251,7 @@ Robot.prototype.start = function() {
}
callback(null, true);
}.bind(this)
], function(err) {
], function(err, results) {
if (!!err) {
Logger.fatal("An error occured while trying to start the robot:");
Logger.fatal(err);
@ -260,6 +260,9 @@ Robot.prototype.start = function() {
}
this.emit('error', err);
}
if (typeof(callback) === 'function') {
callback(err, results);
}
}.bind(this));
return this;
@ -276,8 +279,6 @@ Robot.prototype.startWork = function() {
this.emit('ready', this);
this.work.call(this, this);
this.running = true;
//callback(null, true);
};
// Public: Starts the Robot's connections and triggers a callback