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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -