jonsamwell / angular-http-batcher

Enables HTTP batch request with AngularJS
MIT License
96 stars 28 forks source link

Flushing Requests #7

Closed StephenErstad-zz closed 9 years ago

StephenErstad-zz commented 9 years ago

How does the module handle or support the need to spontaneously send the batch?

For example, on unload we would like to send the most recent batch regardless of quota or time being hit.

jonsamwell commented 9 years ago

Hi,

Currently, there is no way to achieve this however I think it is a good idea so I will add a flush method on the batcher that will flush all pending batches, I think as well if you pass an endpoint url into this function it will just flush that batch. I'll try and do it tonight and let you know.

Jon

jonsamwell commented 9 years ago

Hi,

I've added the flush method as described - there is a little bit of documentation in the Readme.md file.

Let me know if this is what you wanted and if it works in a prod system. I've added some unit tests and works locally.

Immediately flushing all pending requests

In some instances you might want to immediately send all pending request regardless of if the request quota or timeout limit has been reached. To do this you can simply call the flush method on the httpBatcher service and optionally pass in the url of the batch endpoint you want to flush (if no parameter is passed in all pending requests to all endpoints are flushed).

angular.module('myApp', ['jcs.angular-http-batch']);
   .run([
      'httpBatcher',
          function (httpBatcher) {
             httpBatcher.flush();
         }
]);
StephenErstad-zz commented 9 years ago

Awesome! Thank you!