enable async or sync work modes

This commit is contained in:
Adrian Zankich 2014-10-03 23:07:07 -07:00
parent 7f0b5772fa
commit d4ed3117f3
2 changed files with 29 additions and 10 deletions

View File

@ -78,6 +78,13 @@ Cylon.start = function start() {
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();
}
}
};
// Public: Sets the internal configuration, based on passed options

View File

@ -240,20 +240,17 @@ Robot.prototype.start = function() {
return this;
}
var begin = function(callback) {
Logger.info('Working.');
this.emit('ready', this);
this.work.call(this, this);
this.running = true;
callback(null, true);
}.bind(this);
var mode = Utils.fetch(Config, 'workMode', 'async');
Async.series([
this.startConnections,
this.startDevices,
begin
function(callback) {
if (mode === 'async') {
this.startWork();
}
callback(null, true);
}.bind(this)
], function(err) {
if (!!err) {
Logger.fatal("An error occured while trying to start the robot:");
@ -268,6 +265,21 @@ Robot.prototype.start = function() {
return this;
};
// Public: Starts the Robot's work and triggers a callback
//
// callback - callback function to be triggered
//
// Returns nothing
Robot.prototype.startWork = function() {
Logger.info('Working.');
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
//
// callback - callback function to be triggered