Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Is there a way to make my code wait a number of seconds before executing the next piece of code? (API Requests Per Second Limit)

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.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Once you are running async functions you will need to use async/await to do that, setTimeout/Sleep wont work.

if you want a request to end when going to the next code you can do it this way:

async function funcName(){
 const result = await axios.request(options).then(function (response2) {
  message.reply(termargs + " passwords:" + '`' + 
  JSON.stringify(response2.data.found) + '`');
 });

 const result2 = await axios.request(options).then(function (response2) {
  message.reply(termargs + " passwords:" + '`' + 
  JSON.stringify(response2.data.found) + '`');
 });
}

funcName();

on this example first he will end result 1, than go to solve result 2...

Here is the docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want to use setTimeout, you should look after the thread i have linked this thread.

If it doesn't work for you, you could also try the sleep method.

sleep(ms).then(() => {

})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda