Last active
August 29, 2015 14:05
-
-
Save ericeslinger/f2111549574bcfaa3c1b to your computer and use it in GitHub Desktop.
Batch loader with bassmaster
This file contains hidden or 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
angular.module 'clientApp.apiModel.batchRequest', ['ng'] | |
.service 'BatchRequest', ($q, Server, $http, $timeout)-> | |
timeoutPromise = undefined | |
queue = [] | |
postBatch = -> | |
requestQueue = queue.map (req)-> {method: 'GET', path: req.url, deferred: req.deferred} | |
queue = [] | |
timeoutPromise = undefined | |
$http | |
method: 'POST' | |
url: "#{Server.api}/api/batch" | |
data: | |
requests: requestQueue.map (i)->{method: i.method, path: i.path} | |
.then (data)-> | |
requestQueue.forEach (val, i)-> | |
if data.data[i].statusCode? | |
val.deferred.reject(data.data[i]) | |
else | |
val.deferred.resolve(data.data[i]) | |
get: (url)-> | |
deferred = $q.defer() | |
unless timeoutPromise? | |
timeoutPromise = $timeout postBatch, 50 | |
queue.push | |
url: url | |
deferred: deferred | |
return deferred.promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then just make sure you have bassmaster running on your server. I did it with