Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gvt
Created December 18, 2013 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvt/8031654 to your computer and use it in GitHub Desktop.
Save gvt/8031654 to your computer and use it in GitHub Desktop.
class @Api
@request: (cities, cb) ->
requestQueue = []
for (i = 0; i++; i < cities.length)
city = cities[i]
requestQueue[i] = city: city, ended: false
$.get "/city", {name: city}, fnCB(city)
fnCB = (city) ->
(responseBody) ->
currentReq = requestQueue.indexOf (q) ->q.city = city
currentReq.ended = true
if _.all requestQueue, (q) -> q.ended
results = requestQueue.map (x) -> x.population
cb(results)
Api.request "new york", "portland", (results) -> print results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment