I have common scenario but I don't find solution anywhere without a callback method. Here is what I have: from a service method, calling a helper method in another file, from helper calling a worker method which performs a sequence of async operations. they are dependent one another.
let myParentPromise = MyService.serviceFunc(in1, in2);
myParentPromise.then(res => console.log(res));
myParentPromise.catch(exc => console.log(exc));
service layer:
serviceFunc: (in1, in2) => {
return new Promise((resolve, reject) => {
//some processing
let helperPromise = MyHelper.helperFunc(in1,in2);
helperPromise.then(res =>
//processing
{resolve(res)});
helperPromise.catch(exc => {reject(exc)})
})
Helper Layer:
helperFunc: (in1, in2) => {
return new Promise((resolve, reject) =>{
resolve(async1);
}).then(res1 =>{
return async2;
}).then(res2 => {
return res2;
})
}
I want to pass res2 to my service layer then to myParentPromise.
how to do that? Is it possible to do that without using callbacks? I like to purely use promises to do this job.
any help would be appreciated.