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?
class ServiceClass
def initialize(session,...)
@session = session
@user = current_user
end
def update!(username)
@user.username = username
@user.save!
end
...
end
module ApplicationCable
class Channel < ActionCable::Channel::Base
def global_service
@global_service ||= GlobalService.new(current_user)
end
end
end
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.