I have a problem with a PhantomJS script. The script gets a JSON encoded string from a web page and does other things with it. The script:
var address = address;
var amount = 0;
function changeAmount()
{
var page=require('webpage').create();
page.open (address, function(){
//parse json, set amount to something (usually 4)
amount = 4;
});
}
changeAmount();
console.log(amount); //prints 0
//Do stuff with amount
phantom.exit(); //amount not changed yet.
How can I check if the changeAmount function is finished before going forward? Timeout is not possible since I don't know the time it takes to process the changeAmount.