krisleech / wisper

A micro library providing Ruby objects with Publish-Subscribe capabilities
3.27k stars 151 forks source link

Unable to unsubscribe global listeners in Rails 6 when config.cache_classes is false #193

Closed arthurmde closed 1 year ago

arthurmde commented 2 years ago

In a Rails 6 app, when the config cache_classes is false, I'm not able to unsubscribe global listeners declared in an initializer within another process, such as inside a rake task or through the rails console.

For instance. Given the following code inside config/initializers/listeners.rb file

Wisper.subscribe(FooListener)

If I run the rails console and try to unsubscribe the FooListener from Wisper, it won't work:

Wisper.unsubscribe(FooListener)
Wisper::GlobalListeners.registrations.each {|listener| puts listener.inspect} # Display an entry for FooListener

It works as expected when config.cache_classes is true, though. I've just upgraded an app from Rails 5 to 6.

I did not have faced this problem before upgrading from Rails 5. However, I could not find any significant behavior change in cache_classes behavior that would cause the above problem.

Does anybody have an idea what is going on? Is this a bug in wisper?

My current configuration:

krisleech commented 1 year ago

Best to ask this on StackOverflow 👍