Skip to content

Instantly share code, notes, and snippets.

@raidenz
Created May 1, 2017 16:41
Show Gist options
  • Save raidenz/ac3235d36b6cb4454ad186409069d157 to your computer and use it in GitHub Desktop.
Save raidenz/ac3235d36b6cb4454ad186409069d157 to your computer and use it in GitHub Desktop.
coroutines
var co = require('co');
var proc = require('child_process')
function exec(command) {
var p = new Promise(function (resolve, reject) {
proc.exec(command, function (err, stdout, stderr) {
if (err) {
console.log(stderr);
} else {
console.log(stdout)
}
setTimeout(function () {
resolve(true)
}, 3000)
});
});
return p;
}
co(function* () {
var a = yield exec('sudo service postgresql stop')
var b = yield exec('sudo service nginx stop')
var c = yield exec('sudo service redis-server stop')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment