Tuesday, 18 December 2018

node/js noob stuck on async and promises.

Hi - i've just started learning js - having trouble understanding how to solve this problem I am pretty sure it is to do with asynchronous stuff and I'm pretty sure I can solve it with promises/async await - but I cant get it to workI want to connect to the twitter API with node a bunch of times with different parameters and 'get' the tweets from that day.so...getTweets(index, params, processResponses); function getTweets(index, params, callback){ T.get('search/tweets', params, gotData); function gotData(err, data, response) { if(err) return callback(err); list[index].tweets = data.statuses; console.log(list[index].tweets); }; callback(index, list[index].tweets); }Ideally what I want to do is be able to cycle the getTweets function a bunch of times with different indexes and have this update the list with tweets before sending them to process the data. Trouble is it goes on to process the data before the tweets are ready and ends up undefined.any help or explanation as to what I am doing wrong would be very much appreciated. as I said I am new to js so callbacks and promises and asynchronous stuff is still quite confusing to me.thanks in advance.

Submitted December 18, 2018 at 02:35PM by onediplodocus

No comments:

Post a Comment