refactor subscribe resolution

This commit is contained in:
Brian Gough 2019-07-24 14:30:48 +01:00
parent e14a94906a
commit 273af3f3aa
3 changed files with 7 additions and 8 deletions

View file

@ -36,10 +36,7 @@ module.exports = DocumentUpdaterController =
roomEvents.on 'doc-active', (doc_id) -> roomEvents.on 'doc-active', (doc_id) ->
subscribePromises = for rclient in rclientSubList subscribePromises = for rclient in rclientSubList
ChannelManager.subscribe rclient, "applied-ops", doc_id ChannelManager.subscribe rclient, "applied-ops", doc_id
subscribeResult = Promise.all(subscribePromises) RoomManager.emitOnCompletion(subscribePromises, "doc-subscribed-#{doc_id}")
emitResult = (err) => this.emit("doc-subscribed-#{doc_id}", err)
subscribeResult.then () -> emitResult()
subscribeResult.catch (err) -> emitResult(err)
roomEvents.on 'doc-empty', (doc_id) -> roomEvents.on 'doc-empty', (doc_id) ->
for rclient in rclientSubList for rclient in rclientSubList
ChannelManager.unsubscribe rclient, "applied-ops", doc_id ChannelManager.unsubscribe rclient, "applied-ops", doc_id

View file

@ -35,6 +35,11 @@ module.exports = RoomManager =
entity = IdMap.get(id) entity = IdMap.get(id)
@leaveEntity client, entity, 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: () -> eventSource: () ->
return RoomEvents return RoomEvents

View file

@ -42,10 +42,7 @@ module.exports = WebsocketLoadBalancer =
roomEvents.on 'project-active', (project_id) -> roomEvents.on 'project-active', (project_id) ->
subscribePromises = for rclient in rclientSubList subscribePromises = for rclient in rclientSubList
ChannelManager.subscribe rclient, "editor-events", project_id ChannelManager.subscribe rclient, "editor-events", project_id
subscribeResult = Promise.all(subscribePromises) RoomManager.emitOnCompletion(subscribePromises, "project-subscribed-#{project_id}")
emitResult = (err) => this.emit("project-subscribed-#{project_id}", err)
subscribeResult.then () -> emitResult()
subscribeResult.catch (err) -> emitResult(err)
roomEvents.on 'project-empty', (project_id) -> roomEvents.on 'project-empty', (project_id) ->
for rclient in rclientSubList for rclient in rclientSubList
ChannelManager.unsubscribe rclient, "editor-events", project_id ChannelManager.unsubscribe rclient, "editor-events", project_id