Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

avoid multiple async requests when retrieving profile URL.

  • Loading branch information...
commit e227b0180bcd468dd6e0c182ed14a7555c96de5c 1 parent 9d78876
@bnjbvr authored
Showing with 25 additions and 2 deletions.
  1. +25 −2 lib/tent.coffee
View
27 lib/tent.coffee
@@ -14,6 +14,9 @@ class Client
@posts = new PostsModule @
@profile = new ProfileModule @
+ @queue = []
+ @queueBusy = false
+
@credentials = {}
discovery: (cb) ->
@@ -42,7 +45,28 @@ class Client
@
+ queueFree: ->
+ @queueBusy = false
+ @queueEmpty()
+ @
+
+ queueEmpty: ->
+ if not @queueBusy and @queue.length > 0
+ @queueBusy = true
+ f = @queue.pop()
+ f()
+ @
+
getProfile: (cb) ->
+ @queue.push () =>
+ @getProfileLaunch (err, data) =>
+ cb err, data
+ @queueFree()
+
+ @queueEmpty()
+ @
+
+ getProfileLaunch: (cb) ->
if @profiles
cb null, @profiles
return
@@ -57,13 +81,12 @@ class Client
method: 'GET'
rcb = (err, headers, data) =>
@profiles = JSON.parse data
+ @queueFree()
cb null, @profiles
r = new Request reqParam, rcb
r.run()
- @
-
getApiRoot: (cb) ->
@getProfile (err, p) ->
if err
Please sign in to comment.
Something went wrong with that request. Please try again.