Try to run fetch after connect. Fetch is faster than connect, and in console I am getting fetch error because it returns result faster than connection done. But in documentation of async series is a tool to run second function after first returns result.Settimeouts saves situation, but its not beautifull. How can I wait, when all done without promises?
var bets = [];
async.series([
function(callback){
setTimeout(function(){
connect();
callback(null, 'one');
},1)
},
function(callback){
setTimeout(function(){
fetch_last_30();
callback(null, 'two');
},2000)
}
]);
UPD my connect function
function connect(){
var url = "https://api....../login";
/* connect to site and get access_token to access other api*/
$.post(
url,
{username: "000", password : "000"},
function(data){
access_token = data["access_token"];
console.log(data["access_token"]);
}
)
}