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

325
Vistas
Unhandled Rejection while schedule/start a cronjob in a then()

I'm starting Javascript and async programming and I'm stuck with this problem.

I want to collect data from a collection in MongoDB database and schedule/start a cron job with this data.

const startCronJobs = (addressesArray) => {
    for (idx in addressesArray) {
        cron.schedule(('* * * * * ', () => {
            console.log(addressesArray[idx]);
        })).start();
    }
}
const handleConnectedWallets = async () => {
    const docs = await walletModel.find({}); // Retrieve all docs in the collection
    return (docs.map((doc) => { return doc.address }))
}

handleConnectedWallets().then((res) => {
    startCronJobs(res) // If console.log(res) -> ['0x06t...gq', '0x08as...af']
})

And i don't understand why I have the following error:

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "execution must be a function".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

I obviously tried to catch and throw the error after the then() but got the same error.

I must miss something!

Thanks for your help

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

0

You have a pair of parens too many. console.log((x, y)) would only log y.

cron.schedule('* * * * * ', () => {
    console.log(addressesArray[idx]);
}).start();
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