Commit ec777bff authored by nanahira's avatar nanahira

fix multi call in challonge

parent b5486025
...@@ -358,24 +358,32 @@ if settings.modules.challonge.enabled ...@@ -358,24 +358,32 @@ if settings.modules.challonge.enabled
challonge_cache = [] challonge_cache = []
challonge_queue_callbacks = [[], []] challonge_queue_callbacks = [[], []]
is_requesting = [null, null] is_requesting = [null, null]
get_callback = (challonge_type, _callback) -> get_callback = (challonge_type, resolve_data) ->
return ((err, data) -> return ((err, data) ->
if settings.modules.challonge.cache_ttl and !err and data if settings.modules.challonge.cache_ttl and !err and data
challonge_cache[challonge_type] = data challonge_cache[challonge_type] = data
is_requesting[challonge_type] =null is_requesting[challonge_type] =null
_callback(err, data) resolve_data.resolved = true
resolve_data.func(err, data)
while challonge_queue_callbacks[challonge_type].length while challonge_queue_callbacks[challonge_type].length
cur_callback = challonge_queue_callbacks[challonge_type].splice(0, 1)[0] cur_resolve_data = challonge_queue_callbacks[challonge_type].splice(0, 1)[0]
cur_callback(err, data) if !cur_resolve_data.resolved
cur_resolve_data.resolved = true
cur_resolve_data.func(err, data)
return return
) )
challonge.participants._index = (_data) -> challonge.participants._index = (_data) ->
resolve_data = {
func: _data.callback
resolved: false
}
if settings.modules.challonge.cache_ttl and challonge_cache[0] if settings.modules.challonge.cache_ttl and challonge_cache[0]
resolve_data.resolved = true
_data.callback(null, challonge_cache[0]) _data.callback(null, challonge_cache[0])
else if is_requesting[0] and moment() - is_requesting[0] <= 5000 else if is_requesting[0] and moment() - is_requesting[0] <= 5000
challonge_queue_callbacks[0].push(_data.callback) challonge_queue_callbacks[0].push(resolve_data)
else else
_data.callback = get_callback(0, _data.callback) _data.callback = get_callback(0, resolve_data)
is_requesting[0] = moment() is_requesting[0] = moment()
try try
challonge.participants.index(_data) challonge.participants.index(_data)
...@@ -383,12 +391,17 @@ if settings.modules.challonge.enabled ...@@ -383,12 +391,17 @@ if settings.modules.challonge.enabled
_data.callback(err, null) _data.callback(err, null)
return return
challonge.matches._index = (_data) -> challonge.matches._index = (_data) ->
resolve_data = {
func: _data.callback
resolved: false
}
if settings.modules.challonge.cache_ttl and challonge_cache[1] if settings.modules.challonge.cache_ttl and challonge_cache[1]
resolve_data.resolved = true
_data.callback(null, challonge_cache[1]) _data.callback(null, challonge_cache[1])
else if is_requesting[1] and moment() - is_requesting[1] <= 5000 else if is_requesting[1] and moment() - is_requesting[1] <= 5000
challonge_queue_callbacks[1].push(_data.callback) challonge_queue_callbacks[1].push(resolve_data)
else else
_data.callback = get_callback(1, _data.callback) _data.callback = get_callback(1, resolve_data)
is_requesting[1] = moment() is_requesting[1] = moment()
try try
challonge.matches.index(_data) challonge.matches.index(_data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment