breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
2.96k stars 80 forks source link

[fix] Missing await on 'start' function. #218

Open jmtt89 opened 1 year ago

jmtt89 commented 1 year ago

Describe the bug

Node.js version: 18.16

OS version: Win11 (WSL)

Description:

The bug is on the start function, when calling start on already started project, the app will fail and the error can't be cached by try /catch statement, that is because the this.start(job.name) no are waiting...

a good enough solution maybe as call await Promise.all([...]) or just add a await inside the for

 async start(name) {
    ...
    for (const job of this.config.jobs) {
      this.start(job.name);
    }
  }

Code to reproduce

(async () => {
  ....
  await bree.add('boop');
  await bree.start()
  ....
  await bree.add('foo');
  try {
    await bree.start()
  catch (err) {
     // Never call this catch but 
   }
})();

Checklist