Commit ec777bff authored by nanahira's avatar nanahira

fix multi call in challonge

parent b5486025
......@@ -358,24 +358,32 @@ if settings.modules.challonge.enabled
challonge_cache = []
challonge_queue_callbacks = [[], []]
is_requesting = [null, null]
get_callback = (challonge_type, _callback) ->
get_callback = (challonge_type, resolve_data) ->
return ((err, data) ->
if settings.modules.challonge.cache_ttl and !err and data
challonge_cache[challonge_type] = data
is_requesting[challonge_type] =null
_callback(err, data)
resolve_data.resolved = true
resolve_data.func(err, data)
while challonge_queue_callbacks[challonge_type].length
cur_callback = challonge_queue_callbacks[challonge_type].splice(0, 1)[0]
cur_callback(err, data)
cur_resolve_data = challonge_queue_callbacks[challonge_type].splice(0, 1)[0]
if !cur_resolve_data.resolved
cur_resolve_data.resolved = true
cur_resolve_data.func(err, data)
return
)
challonge.participants._index = (_data) ->
resolve_data = {
func: _data.callback
resolved: false
}
if settings.modules.challonge.cache_ttl and challonge_cache[0]
resolve_data.resolved = true
_data.callback(null, challonge_cache[0])
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
_data.callback = get_callback(0, _data.callback)
_data.callback = get_callback(0, resolve_data)
is_requesting[0] = moment()
try
challonge.participants.index(_data)
......@@ -383,12 +391,17 @@ if settings.modules.challonge.enabled
_data.callback(err, null)
return
challonge.matches._index = (_data) ->
resolve_data = {
func: _data.callback
resolved: false
}
if settings.modules.challonge.cache_ttl and challonge_cache[1]
resolve_data.resolved = true
_data.callback(null, challonge_cache[1])
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
_data.callback = get_callback(1, _data.callback)
_data.callback = get_callback(1, resolve_data)
is_requesting[1] = moment()
try
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