javascript - Trying to run a function after a promise fail in array -
javascript - Trying to run a function after a promise fail in array -
i have array of promises , function need phone call after promises complete. however, whenever single promise fails out of array, $q.all(promise) not launch callback function.
function searchlibraries(library) { //console.log(library); console.log('inside searchlibraries'); var librarycount = library.length; (var = 0; < librarycount; i++) { //console.log(i,library[i].siteurl,library[i].listid,library[i].listname) itempromise[i] = $().spservices({ operation: "getlistitems", weburl: library[i].siteurl, listname: library[i].listid, camlviewfields: cviewfieldslimited, camlquery: cqueryallcheckedoutdocuments, camlqueryoptions: cqueryoptions, cachexml:true, completefunc: function (xdata,status){ if($(xdata).hassperror()){ console.log("error"); console.log("error code:" ,$(xdata).getsperrorcode()); console.log("error message:" ,$(xdata).getsperrortext()); } } }) } homecoming $q.all(itempromise).then(parsesearchresult); }
.then()
takes multiple arguments. sec argument function reference called if promise fails. can supply sec argument in
$q.all(itempromise).then(sucesshandler, failhandler)`
in q promise library, might want utilize .allsettled()
notified when promises have finished, if fail. details how works here. utilize bluebird promise library offers .settle()
.
javascript angularjs promise angular-promise
Comments
Post a Comment