forked from richmarr/stagecoach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (47 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var argv = require('./lib/argv');
var propagit = require('propagit');
var EventEmitter = require('events').EventEmitter;
function Commands (opts) {
this.opts = opts
}
Commands.prototype.ps = function (cb) {
var p = propagit(this.opts);
p.on('error', function (err) {
cb(err);
});
p.hub.on('up', function (hub) {
var em = new EventEmitter;
var obj = {};
em.on('data', function (key, procs) {
obj[key] = procs
});
em.on('end', function () {
cb(null, obj)
});
hub.ps(em.emit.bind(em));
});
}
Commands.prototype.stop = function (pid, cb) {
var self = this;
var p = propagit(self.opts);
var called = false;
p.on('error', function (err) {
if (!called) cb(err);
called = true;
});
p.hub(function (hub) {
var opts = {
drone : self.opts.drone,
drones : self.opts.drones,
pid : pid
};
hub.stop(opts, function (drone) {
p.hub.close();
if (!called) cb(null, drone);
called = true;
});
});
}
module.exports = function (opts) {
return new Commands(opts);
}