I'm fairly new to JS, this being my first project in it (using sqlite and the twitter api). I've been stuck for a while now on this issue. I can get await and async to work fine in other test programs but when it comes to this one the await within the following function isn't waiting for getmin() to conclude before moving on, which is causing issues in my for loop.
In the same vein like I said this is my first js project, it's highly likely to be wildly unoptimised. If something stands out as inefficient to you let me know and I'll know for future what to do/avoid.
async function following(err, data, response) {
if (err) {
console.log(err)
} else {
for (let i = 0; i < data.users.length; i++){
let user = data.users[i]
userinfo.name = user.name
userinfo.screen_name = user.screen_name
userinfo.user_ID = user.id
maxparams.user_id = user.id
new_min_params.user_id = user.id
console.log(new_min_params)
x = await getmin()
console.log(x)
// T.get('statuses/user_timeline', maxparams, getmax)
// T.get('statuses/user_timeline', tweetparams, gettweets)
//databasedata = [data.users.screen_name, minTweetID, maxTweetID]
}
// console.log(response_dictionary)
// console.log("")
cursorscore = 0
}
function getmin() {
let sql = `SELECT MaxTweetID FROM following WHERE Handle = ?`;
db.get(sql, [userinfo.screen_name], (err, row) => {
if (err) {
return console.error(err.message);
} else {
return (row ? updatemin(userinfo.screen_name) : T.get('statuses/user_timeline', new_min_params, get_tenth_tweet))
}});
}