enable async or sync work modes
This commit is contained in:
parent
7f0b5772fa
commit
d4ed3117f3
|
@ -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
|
||||
|
|
32
lib/robot.js
32
lib/robot.js
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue