title: Abort Xhr on cujojs rest.js
body: <p>I'm using <a href="https://github.com/cujojs/rest" rel="nofollow">cujojs/rest</a> to send requests to my (laravel) API. I'm looking for a way to cancel requests that are not over when a new one comes in.</p>
  
  <p>There is a cancel method on the client which may be what I need to solve my problem :</p>
  
  <p>My app displays a paginated collection of items, people can browse pages by clicking a "next/prev" button.
  If the user clicks multiple times on the 'next' button quickly every new page will fire of a new request. I'd like to make sure that only the latest request gets going and all the other (unfinished) ones are aborted.</p>
  
  <p>I used to do this with a beforeSend method when I was using another tool to perform my requests. It would add the xhr object to an array and before a request was fired it would call .abort() on all the xhr in that array if they were not over.</p>
  
  <p>Now that I switched to cujojs/rest, I can't figure out how the cancel method could be used to accomplish that.</p>
  
  <p>Of course I don't want to abort any request before a new one is run, just the ones that tap the same resource as I might have unrelated data loading elsewhere.</p>
  
  <pre><code>/users?page=1 -&gt; should be canceled
  /users?page=2 -&gt; should be canceled
  /preferences  -&gt; should NOT be canceled
  /users?page=3 -&gt; should be canceled
  /users?page=4 -&gt; should go through as its the last one
  </code></pre>
  
  <p>Any help would be very appreciated.</p>