I have parent function which return Promise. In parent function I'm using bluebird-retry package to execute another (nested) promise which just for development purposes currently always reject.
So I'm calling function parent
which execute 4 times child
. Parent function code is:
const parent = () => {
return new Promise((resolve, reject, onCancel) => {
setTimeout(async() => {
console.log('CALLED PARENT');
try {
await retry(child, { max_tries: 4, interval: 500 })
} catch (e) {
reject(new Error('Rejected from parent function'));
}
},100);
onCancel(() => {
console.log('Registered cancel in parent function');
retry.StopError(new Error('Stop retrying child'));
reject(new Error('Cancelled parent'));
});
});
};
So if child()
always reject it would try 4 times and after 2100ms (100ms timeout and 4 x 500ms interval) would reject error.
However after 2000ms I'm calling bluebird .cancel
method on promise returned from parent function.
Inside above parent function I have onCancel which suppose to stop retrying and reject error. However this does not work as expected because it doesn't stop retrying. Output of my code is:
CALLED PARENT
CALLED CHILD
CALLED CHILD
CALLED CHILD
Registered cancel in parent function
Emit stop::all event
Caught stop::all event
CALLED CHILD
but it suppose to be without last 'CALLED CHILD'.