Search Posts

Category: promise

How to wait/finish multiple insert function in for each loop?

how to do this asynchronously, print console.log(“PRINT THIS, AFTER ALL LOOP IS DONE”) i have forEach inside forEach. InsertService does not return any value, i just want to insert here. i don’t know how to apply $q and $q.all. pls help. angular.forEach(MAIN, function (value, key) { //#1 SelectService1.SelectID( (res) { angular.forEach(res, function (value, key) { InsertService1.Insert(value).then(function (res) { console.log(“NEW INSERTED Service 1!”); }, function (err) { }); }); }, function (err) { }); //#2 SelectService2.SelectID( […]

Controlling flow with nested promises in loop

I’m having trouble controlling the flow of my method using promises: //FIND CHECKED OUT FILES getCheckedOutFiles = function () { console.log(‘Get checked out files’); var d = $q.defer(); // Store final results and pass to then callback var checkedOutFiles = window.x = []; // Promise, returns collection with all sites SiteService.getAllSites() .then(sites => { // For each site get lists then get items matching filter sites.forEach(function (site) { var web = new $pnp.Web(site.url); return web.lists […]

CodeIgniter 3 Implement Promise

My CI app makes API call to third party Rest API server which will be consumed by front end. At first, front end app will hit my CI app and which in turn will hit third party LogInAPI(session valid for 15 mins), and after login we need to hit subsequent API calls by passing the key(response of loginApi) in header. So basically I need to hit loginAPI for every 15 minutes. I am trying angular […]

loop until promise function give result

I’m looking to loop on a promise function until I have the result I want. As of now I’m using recursivity like this: function pull() { dataFactory.pullFunction().then(function(res) { pull() }) } But that’s giving me some front-end/style bugs for my loading bar for example. I would do something like this: function pull() { while (res.status == ‘ONGOING’) { dataFactory.pullFunction().then(function(res) { // my stuffs }) } } But when I try it the pullFunction() is never […]