I´m creating a small Node.js application for some monitoring stuff. The following operation has to be made with this app:
A job scheduler (using node-schedule module) is retrieving data from a web service within a time period and inserting the content into an array (for further processing). After finishing the job a promise should resolve the complete array in order to use it in my main program.
Here is my coding so far. With this coding the promise gets resolved before finishing the job and the array is empty. Can you give me any hints how to solve this?
async function dataRetrieval(start, end, rule){
let array = [];
return new Promise(function (resolve) {
schedule.scheduleJob({start: start, end: end, rule: rule}, async function (){
let data = await service.getData();
array.push(data);
});
resolve(array);
});
}