Let’s assume we use something like current_user which is an instance of a ServiceClass which holds user model, session params and other info.
The thing is that variable is being set during connection with websocket and being reused for all AC calls on different subscriptions.
Then, at some point user decides to update his username, we make a call to current_user.update(new_username) and it works okay.
But other AC subscriptions under that user still use old user model. I suppose as each subscription works under their own thread, thus updating user model under one thread will not update them under other threads. What is the best approach for such case?
@session = session
@user = current_user
@user.username = username
class Channel < ActionCable::Channel::Base
def global_service @global_service ||= GlobalService.new(current_user) end