Created
June 15, 2012 11:05
-
-
Save jonpacker/2935895 to your computer and use it in GitHub Desktop.
Solving callback soup with async.js
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 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(); | |
}); | |
}); | |
}); | |
}); | |
}); | |
} |
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 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