Hello all.

I am planning on using ActiveSupport::Notifications and have a question 
about threading. For the purposes of this question I am assuming 
config.threadsafe! is enabled. 

Will a subscriber execute in the same thread as the code that caused it to 
be triggered or do they run in separate threads? 

The reason I ask is that I would like to do something like

In Controller Code:

def action
  Module.events[Thread.current] = Event.new # Module.events returns a hash
  # rest of action code
end

And elsewhere:

ActiveSupport::Notifications.subscribe "process_action.action_controller" 
do |name, start, finish, id, payload|
  event = Module.events[Thread.current] # returns the Event that was 
created in the controller.
  # Do processing on event
end

Obviously if the Subscriber runs in a different thread then this will not 
work since Thread.current will not match so I wanted to check. Note that in 
this case I do not want to pass the Event as part of the payload because I 
want to be able to use existing rails built-in notifications without having 
to modify them.

Cheers

Jeff




-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/1V_DB1nyqkMJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to