I´m new in Node.js and just learn the basics in using Promises and async functions. Currently I´m struggling to achieve a return from a nested function using Promises. Although there are similar questions to (I think the same issue), I still don´t get it working. Here´s what I want to achieve.
With the function jobScheduler I create a new job using the node-schedule module which is retrieving data from a service between two dates (variables start and end) with an specific recurrence rule (variable rule). The service is returning data in form of true / false (which is working properly). And now I need to return this value of the service by the jobScheduler function with a promise. The job scheduler is working perfectly as it should, I´m just struggeling to return the true / false value by my jobScheduler function.
function jobScheduler(start, end, rule, cycle) {
return new Promise(function (resolve, reject) {
schedule.scheduleJob({start: start, end: end, rule: rule}, async function () {
const data = await service.getData(cycle);
resolve(data);
});
});
}