Clean up starter and #stop functions
This commit is contained in:
parent
862a3702b7
commit
5650ce1d60
47
lib/robot.js
47
lib/robot.js
|
@ -186,13 +186,13 @@ namespace("Cylon", function() {
|
|||
//
|
||||
// Returns the result of the work
|
||||
Robot.prototype.start = function() {
|
||||
var _this = this;
|
||||
var self = this;
|
||||
return this.startConnections(function() {
|
||||
return _this.robot.startDevices(function() {
|
||||
_this.robot.work.call(_this.robot, _this.robot);
|
||||
_this.running = true;
|
||||
return self.robot.startDevices(function() {
|
||||
self.robot.work.call(self.robot, self.robot);
|
||||
self.running = true;
|
||||
Logger.info("Working...");
|
||||
return _this.robot.emit('working');
|
||||
return self.robot.emit('working');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -203,15 +203,16 @@ namespace("Cylon", function() {
|
|||
//
|
||||
// Returns nothing
|
||||
Robot.prototype.startConnections = function(callback) {
|
||||
var connection, n, starters, _ref;
|
||||
var starters = {}
|
||||
|
||||
Logger.info("Starting connections...");
|
||||
starters = {};
|
||||
_ref = this.connections;
|
||||
for (n in _ref) {
|
||||
connection = _ref[n];
|
||||
|
||||
for (var n in this.connections) {
|
||||
var connection = this.connections[n];
|
||||
this.robot[n] = connection;
|
||||
starters[n] = connection.connect;
|
||||
}
|
||||
|
||||
return Async.parallel(starters, callback);
|
||||
};
|
||||
|
||||
|
@ -221,15 +222,16 @@ namespace("Cylon", function() {
|
|||
//
|
||||
// Returns nothing
|
||||
Robot.prototype.startDevices = function(callback) {
|
||||
var device, n, starters, _ref;
|
||||
var starters = {}
|
||||
|
||||
Logger.info("Starting devices...");
|
||||
starters = {};
|
||||
_ref = this.devices;
|
||||
for (n in _ref) {
|
||||
device = _ref[n];
|
||||
|
||||
for (var n in this.devices) {
|
||||
var device = this.devices[n];
|
||||
this.robot[n] = device;
|
||||
starters[n] = device.start;
|
||||
}
|
||||
|
||||
return Async.parallel(starters, callback);
|
||||
};
|
||||
|
||||
|
@ -239,19 +241,8 @@ namespace("Cylon", function() {
|
|||
//
|
||||
// Returns nothing
|
||||
Robot.prototype.stop = function() {
|
||||
var connection, device, n, _ref, _ref1, _results;
|
||||
_ref = this.devices;
|
||||
for (n in _ref) {
|
||||
device = _ref[n];
|
||||
device.stop();
|
||||
}
|
||||
_ref1 = this.connections;
|
||||
_results = [];
|
||||
for (n in _ref1) {
|
||||
connection = _ref1[n];
|
||||
_results.push(connection.disconnect());
|
||||
}
|
||||
return _results;
|
||||
for (var d in this.devices) { this.devices[d].stop(); }
|
||||
for (var c in this.connections) { this.connections[c].stop(); }
|
||||
};
|
||||
|
||||
// Public: Initialize an adaptor and adds it to @robot.adaptors
|
||||
|
|
Loading…
Reference in New Issue