Here I'm feeling stucked with some asynchronous code that should run inside a casper.then()
callback.
casper.then(function() {
var spawn = require("child_process").spawn;
var child = spawn("somecommand", ["somearg"]);
child.stdout.on("data", function (data) {
console.log("spawnSTDOUT:", JSON.stringify(data))
});
});
casper.then(function () {
// Something that should be synchonized
});
Is there any way to make sure that the second then()
will be executed only after the data callback fires up?
I'd love to replace the first then()
with something that will not pass the control to second then()
after execution by default, and would rather do this by calling something (let's call it 'resolve' as the promise pattern suggests) in the data callback.
Examples that are making use of casper.waitFor()
are also appreciated, but I'd receive a sort of 'common practice' suggestion in that case.