Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

323
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!