An Angularjs module that is able to limit requests at the same time.
- angularjs
bower install ngHttpPool
angular.module( "app", [
"ngHttpPool"
]).controller('ctrl',function( httpPool ){
});
Limit max request amounts by contructor:
var pool = httpPool.create( 2 );
Set a http config by map
function:
pool.map({method:"get",url:"/"});
Optionally, specify success and fail callbacks:
pool.map({method:"get",url:"/"}, success, error);
Create a defer
.
pool.listen()
Add and run requests to pool.
for( var index = 0; index<10 ; index++ ){
pool.map({method:"get",url:"/",params:{id:index}});
}
Get a promise of callbacks.
var promise = pool.Promise();
promise.then(function(){
console.log( "all of the callbacks." );
});
Clone this project.
git clone http://github.com/SparrowJang/ngHttpPool.git
cd ngHttpPool
Install the express framework and grunt modules.
npm install
run a server:
grunt server
Finally,open your brower,enter http://localhost:3000/demo/index.html.