Created
May 1, 2017 16:41
-
-
Save raidenz/ac3235d36b6cb4454ad186409069d157 to your computer and use it in GitHub Desktop.
coroutines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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