Skip to content

Instantly share code, notes, and snippets.

@jonpacker
Created June 15, 2012 11:05
Show Gist options
  • Save jonpacker/2935895 to your computer and use it in GitHub Desktop.
Save jonpacker/2935895 to your computer and use it in GitHub Desktop.
Solving callback soup with async.js
var refreshDb = function(done) {
spawn(neo4j, ['stop']).on('exit', function() {
spawn('rm', ['-rf', datapath]).on('exit', function() {
spawn('mkdir', ['-p', datapath]).on('exit', function() {
updateConf(TEST_INSTANCE_PORT, function() {
var n = spawn(neo4j, ['start'])
n.stdout.on('data', function(d) {
process.stdout.write(d.toString());
})
n.on('exit', function() {
done();
});
});
});
});
});
}
var refreshDb = function(done) {
async.series([
function stopNeo(next) {
spawn(neo4j, ['stop']).on('exit', function() { next(); })
},
function removeDataDir(next) {
spawn('rm', ['-rf', datapath]).on('exit', function() { next(); });
},
function recreateDatDir(next) {
spawn('mkdir', ['-p', datapath]).on('exit', function() { next(); });
},
function updateConfiguration(next) {
updateConf(TEST_INSTANCE_PORT, next);
},
function startNeo(next) {
var n = spawn(neo4j, ['start'])
n.stdout.on('data', function(d) {
process.stdout.write(d.toString());
})
n.on('exit', function() { next(); });
}
], done);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment