Created
September 1, 2016 07:45
-
-
Save hash-bang/652be06e3cf89f9d71fa2dfceb893719 to your computer and use it in GitHub Desktop.
angular-q-limit Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This example uses a dynamic array of items, creating a promise for each and finally executing them via $q.limitAll with a maximum of 3 items running concurrently | |
// Assumes SomeModel is a promise based structure like $http or ngResource | |
var stuff = [ // Very big array of things to request // ]; | |
$q.limitAll(3, | |
stuff.map(function(item) { | |
return SomeModel.get({id: item}).$promise; | |
}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This example runs 3 defined promise limited to 1 item of concurrency (yes you could just use .then().then().then() but thats not the point) | |
// Assumes SomeModel1-3 is a promise based structure like $http or ngResource | |
$q.limitAll(1, [ | |
function() { | |
return SomeModel1.query().$promise | |
.then(data => $scope.data1 = data); | |
}, | |
function() { | |
return SomeModel2.query().$promise | |
.then(data => $scope.data2 = data); | |
}, | |
function() { | |
return SomeModel3.query().$promise | |
.then(data => $scope.data3 = data); | |
}, | |
]).then(function() { // All done // }}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment