mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
refactor subscribe resolution
This commit is contained in:
parent
e14a94906a
commit
273af3f3aa
3 changed files with 7 additions and 8 deletions
|
@ -36,10 +36,7 @@ module.exports = DocumentUpdaterController =
|
|||
roomEvents.on 'doc-active', (doc_id) ->
|
||||
subscribePromises = for rclient in rclientSubList
|
||||
ChannelManager.subscribe rclient, "applied-ops", doc_id
|
||||
subscribeResult = Promise.all(subscribePromises)
|
||||
emitResult = (err) => this.emit("doc-subscribed-#{doc_id}", err)
|
||||
subscribeResult.then () -> emitResult()
|
||||
subscribeResult.catch (err) -> emitResult(err)
|
||||
RoomManager.emitOnCompletion(subscribePromises, "doc-subscribed-#{doc_id}")
|
||||
roomEvents.on 'doc-empty', (doc_id) ->
|
||||
for rclient in rclientSubList
|
||||
ChannelManager.unsubscribe rclient, "applied-ops", doc_id
|
||||
|
|
|
@ -35,6 +35,11 @@ module.exports = RoomManager =
|
|||
entity = IdMap.get(id)
|
||||
@leaveEntity client, entity, id
|
||||
|
||||
emitOnCompletion: (promiseList, eventName) ->
|
||||
result = Promise.all(promiseList)
|
||||
result.then () -> RoomEvents.emit(eventName)
|
||||
result.catch (err) -> RoomEvents.emit(eventName, err)
|
||||
|
||||
eventSource: () ->
|
||||
return RoomEvents
|
||||
|
||||
|
|
|
@ -42,10 +42,7 @@ module.exports = WebsocketLoadBalancer =
|
|||
roomEvents.on 'project-active', (project_id) ->
|
||||
subscribePromises = for rclient in rclientSubList
|
||||
ChannelManager.subscribe rclient, "editor-events", project_id
|
||||
subscribeResult = Promise.all(subscribePromises)
|
||||
emitResult = (err) => this.emit("project-subscribed-#{project_id}", err)
|
||||
subscribeResult.then () -> emitResult()
|
||||
subscribeResult.catch (err) -> emitResult(err)
|
||||
RoomManager.emitOnCompletion(subscribePromises, "project-subscribed-#{project_id}")
|
||||
roomEvents.on 'project-empty', (project_id) ->
|
||||
for rclient in rclientSubList
|
||||
ChannelManager.unsubscribe rclient, "editor-events", project_id
|
||||
|
|
Loading…
Reference in a new issue