gameKeys iteration
This commit is contained in:
parent
c1f25d008b
commit
bfbd1cbf0a
1 changed files with 33 additions and 3 deletions
|
@ -81,9 +81,39 @@ class FFTCGSESSION
|
||||||
reject null
|
reject null
|
||||||
|
|
||||||
else
|
else
|
||||||
# return game ID
|
# add game to active set
|
||||||
logger.info "OK '#{@gameKey digest}' created"
|
@db.sadd (@gameKey 'active'), (@gameKey digest), (err, res) =>
|
||||||
resolve digest
|
# return game ID
|
||||||
|
logger.info "OK '#{@gameKey digest}' created"
|
||||||
|
resolve digest
|
||||||
|
|
||||||
|
getGames: ->
|
||||||
|
# function to return all active gameKeys
|
||||||
|
activeGameKeys = (set, cursor) =>
|
||||||
|
# start iteration
|
||||||
|
set ?= new Set()
|
||||||
|
cursor ?= '0'
|
||||||
|
|
||||||
|
return new Promise (resolve, reject) =>
|
||||||
|
# scan "active" gameKey
|
||||||
|
@db.sscan (@gameKey 'active'), cursor, 'COUNT', '100', (err, res) =>
|
||||||
|
|
||||||
|
# add to results set
|
||||||
|
cursor = res[0]
|
||||||
|
for key in res[1]
|
||||||
|
set.add key
|
||||||
|
|
||||||
|
if cursor == '0'
|
||||||
|
# done on cursor = 0
|
||||||
|
resolve set
|
||||||
|
else
|
||||||
|
# recursive call (resolve one step deeper)
|
||||||
|
allGames set, cursor
|
||||||
|
.then (set) =>
|
||||||
|
resolve set
|
||||||
|
|
||||||
|
activeGameKeys().then (set) =>
|
||||||
|
logger.info "game count: #{Array.from(set).length}"
|
||||||
|
|
||||||
joinGame: (digest, userid) ->
|
joinGame: (digest, userid) ->
|
||||||
new Promise (resolve, reject) =>
|
new Promise (resolve, reject) =>
|
||||||
|
|
Reference in a new issue