Class: Hibiki::Rails::Registry
- Inherits:
-
Object
- Object
- Hibiki::Rails::Registry
- Defined in:
- lib/hibiki/rails/registry.rb
Overview
Tracks every live hibiki channel in the process so the Rails reloader can tear them down: a long-lived graph holds blocks bound to the class versions it was built from, so surviving a code reload would mean effects running stale code forever.
NOTE: the core's no-mutex rule is about the GRAPH (confinement, see hibiki's docs-md/threading-model.md). This is glue infrastructure touched from many cable threads; a lock is the right tool here.
Instance Method Summary collapse
-
#dispose_all ⇒ Object
Close each distinct cable connection, which routes every one of its channels through the normal unsubscribed path — dispose root, stop actor, unregister — so teardown has exactly ONE code path and idempotency comes free.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(channel) ⇒ Object
- #size ⇒ Object
- #unregister(channel) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
14 15 16 17 |
# File 'lib/hibiki/rails/registry.rb', line 14 def initialize @lock = Mutex.new @channels = Set.new end |
Instance Method Details
#dispose_all ⇒ Object
Close each distinct cable connection, which routes every one of its channels through the normal unsubscribed path — dispose root, stop actor, unregister — so teardown has exactly ONE code path and idempotency comes free. Clients auto-reconnect, resubscribe, and #build_graph reruns on fresh class versions; graph state resets, which is inherent to a remount (LiveView does the same).
37 38 39 40 |
# File 'lib/hibiki/rails/registry.rb', line 37 def dispose_all channels = @lock.synchronize { @channels.to_a } channels.map(&:connection).uniq.each(&:close) end |
#register(channel) ⇒ Object
19 20 21 |
# File 'lib/hibiki/rails/registry.rb', line 19 def register(channel) @lock.synchronize { @channels << channel } end |
#size ⇒ Object
27 28 29 |
# File 'lib/hibiki/rails/registry.rb', line 27 def size @lock.synchronize { @channels.size } end |
#unregister(channel) ⇒ Object
23 24 25 |
# File 'lib/hibiki/rails/registry.rb', line 23 def unregister(channel) @lock.synchronize { @channels.delete(channel) } end |