setTimeout() doesn't seem to work, and I've read up on why and I understand. Something about it being asynchronous, so it doesn't delay the other functions in your code from running. So how can I make it so that it waits a few seconds before sending out another axios.request? And the reason I'm asking about this is because the API im requesting only allows one request per second.
setTimeout(function () {
axios.request(options).then(function (response) {
for (let i = 0, l = response.data["result"].length; i < l; i++) {
var obj = response.data.result;
console.log(response.data.result[i].hash);
}
options.params.term = obj[1].hash
options.params.func = 'dehash'
setTimeout(function () {
axios.request(options).then(function (response2) {
message.reply(termargs + " passwords:" + '`' + JSON.stringify(response2.data.found) + '`');
});
}, 1250);
options.params.term = obj[2].hash
setTimeout(function () {
axios.request(options).then(function (response3) {
message.reply(termargs + " passwords:" + '`' + JSON.stringify(response3.data.found) + '`');
});
}, 1250);
options.params.term = obj[3].hash
setTimeout(function () {
axios.request(options).then(function (response4) {
message.reply(termargs + " passwords:" + '`' + JSON.stringify(response4.data.found) + '`');
});
}, 1250);
}).catch(function (error) {
message.reply("There was an error!" + '`' + 'Couldnt find user.' + '`');
console.log(error);
});
}, 1250);
I'm going to reiterate the fact that I'm new to Javascript, and this no wait function thing really makes my toes curl, as I use it all the time in the other programming language called Lua.