Question: // Javascript Hi!Iamstuckinthisquestion.Cansomeonehelp,please? Implementafunctionnamed`retried`thattakesanasynchronousfunctionas inputandreturnsanewasynchronousfunctionthatcallstheprovided functionuntilitsucceeds;theretriedfunctionshouldthensucceedwith thesamevalue.Ifafter3attemptstheprovidedfunctionisstillfailing theretriedversionshouldfailwiththemostrecentfailure. Forthesakeofthisexerciseanasynchronousfunctionisafunctionwith exactlytwoarguments:anonSuccesscallbackandanonFailurecallback. Eachcallbacktakesasingleparameter.Anasynchronousfunctiondoesnot returnvalue,insteaditcallstheappropriatecallbackwithavalueoran errorobject. Anexampleofcallinganasynchronousfunctionnamed`listCars`wouldbe: functionlogCars(cars) {console.log(found cars,cars); } functionalertError(error) {alert(Error:+error); } listCars(logCars,alertError); Thesameretriedcallwouldbe: varretriedListCars=retried(listCars); retriedListCars(logCars,alertError);
// Javascript
Hi!Iamstuckinthisquestion.Cansomeonehelp,please?
Implementafunctionnamed`retried`thattakesanasynchronousfunctionas
inputandreturnsanewasynchronousfunctionthatcallstheprovided
functionuntilitsucceeds;theretriedfunctionshouldthensucceedwith
thesamevalue.Ifafter3attemptstheprovidedfunctionisstillfailing
theretriedversionshouldfailwiththemostrecentfailure.
Forthesakeofthisexerciseanasynchronousfunctionisafunctionwith
exactlytwoarguments:anonSuccesscallbackandanonFailurecallback.
Eachcallbacktakesasingleparameter.Anasynchronousfunctiondoesnot
returnvalue,insteaditcallstheappropriatecallbackwithavalueoran
errorobject.
Anexampleofcallinganasynchronousfunctionnamed`listCars`wouldbe:
functionlogCars(cars) {console.log("found cars",cars); }
functionalertError(error) {alert("Error:"+error); }
listCars(logCars,alertError);
Thesame"retried"callwouldbe:
varretriedListCars=retried(listCars);
retriedListCars(logCars,alertError);
ThisiswhatIhavedone:
functiononSuccess(data) {
console.log("Success =>",data)
}
functiononFailure(data) {
console.log("Error =>",data)
}
asyncfunctionretriedCallback(onSuc,onFail) {
console.log("number =>")
leterror=false
if(!error) {
onSuc({data:"SUCESS:"})
}else{
onFail({data:"FAILURE:"})
}
}
functionretried(retriedCallback) {
letcount=3
returnasyncfunction(onS,onF) {
//TODO: calls the retriedCallback until it succeeds; the retried (async?)function should then
// succeed with the same value. If after 3 attempts the provided function is still failing
//the retried (async?) version should fail with the most recent failure.
//tldr: how do I check if etriedCallback was success or failer?
console.log("start")
while(count--) {
letx=awaitretriedCallback(onS,onF)
}
console.log("done")
}
}
letretire=retried(retriedCallback)
retire(onSuccess,onFailure)
Anysuggestion?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
