darkterra / mongo-scheduler

Persistent event schedule for node.js using mongo as storage
MIT License
8 stars 8 forks source link

list() method not returning events #16

Closed waheedmoeed closed 3 years ago

waheedmoeed commented 3 years ago

scheduler.list() method not returning any error or result. let response = await scheduler.list()

darkterra commented 3 years ago

Hello @waheedmoeed !

Yes, this is quite normal, the "list" function expects a callback, look the doc: https://github.com/darkterra/mongo-scheduler#schedulerlist.

However if you absolutely want to use Async / Await, you can wrap the "list" method with a function that returns a promise.

Ex:

async function getSchedulerList(options) {
  return new Promise((resolve, reject) => {
    scheduler.list(options, (err, events) => {
      if (err) {
        reject(err);
      }
      else {
        resolve(events);
      }
    });
  });
};

Do not hesitate if you have other questions :)

darkterra commented 3 years ago

If you have no other questions, I close this issue. Do not hesitate to let me know if the explanation is sufficiently clear and if the solution I am proposing suits you.

darkterra commented 3 years ago

Hello @waheedmoeed, I made a new update of the module. Now you can direct call function list with Async / Await call.

For more info, check this version: https://github.com/darkterra/mongo-scheduler/tree/v2.3.0