I have some async work that can fail and be rejected. I would like to retry until it gets resolved. Have found this approach but cant make it work. dontGiveUp(doFirst) gives me: Uncaught TypeError: f.then is not a function(…)
Can someone point the errors/or better aproach?
function dontGiveUp(f) {
return f.then(
undefined,
function (err) {
return dontGiveUp(f);
}
);
}
function doFirst(In){
return new Promise(function(resolve, reject) {
console.log("doFirst Done" + In);
if (Math.random() >= 0.5) {
console.log("resolve");
resolve(In);
}
else
{
console.log("reject");
reject(In);
}
})
}