solid_cable 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ff4e7b967cec58b0387f709a050e30db6a5d0223f070a63d878242877780c49
4
- data.tar.gz: b3ff5a3c70b6594075e311b16ab165bce984a0eb41f1c9be2c2a34e23eccc738
3
+ metadata.gz: 807dfe75fdc4577c47485b8af3a296eddc6655f53d2294bc831fc1862127214e
4
+ data.tar.gz: 48b1b21d6e60e0532f6a7ea542e3cda8384d4178256c81cffa184c4bebaee721
5
5
  SHA512:
6
- metadata.gz: 771044684f961dad0116e7769ac429d06ce613d5779809818a81146a585ef4ffeda081533031a7c90767e6e0cd913478b2ffb3117e1d9886bae48d6b9e6c9459
7
- data.tar.gz: 18b65de8a357d40af82bbf0d749ca43dcd864fe8e06b074701c97cbdf37eef3e6aa5f36178b51c853612d14688d1d51d99c395ba894171d73f097a18112daeb0
6
+ metadata.gz: '099db3f19f50a76ea75881f3a01efc73a0ae1a60aee20cce9f8be0e06dc9cfe3de5beb574a212cc34d2eca33103e367d4d09a649340b49777c76bda09bb04320'
7
+ data.tar.gz: e519ed0fcd86350fd107db0d90717466676029f9471f26b9544bd970684d39993b0585b8d4c848b482bca21aa2924de4f8790655f7a36c4cb0d7bc10c5f91610
@@ -3,6 +3,7 @@
3
3
  require "action_cable/subscription_adapter/base"
4
4
  require "action_cable/subscription_adapter/channel_prefix"
5
5
  require "action_cable/subscription_adapter/subscriber_map"
6
+ require "concurrent/atomic/semaphore"
6
7
 
7
8
  module ActionCable
8
9
  module SubscriptionAdapter
@@ -38,34 +39,53 @@ module ActionCable
38
39
  end
39
40
 
40
41
  class Listener < ::ActionCable::SubscriptionAdapter::SubscriberMap
42
+ Stop = Class.new(Exception)
43
+
41
44
  def initialize(event_loop)
42
45
  super()
43
46
 
44
47
  @event_loop = event_loop
45
48
 
49
+ # Critical section begins with 0 permits. It can be understood as
50
+ # being "normally held" by the listener thread. It is released
51
+ # for specific sections of code, rather than acquired.
52
+ @critical = Concurrent::Semaphore.new(0)
53
+
46
54
  @thread = Thread.new do
47
- Thread.current.abort_on_exception = true
48
55
  listen
49
56
  end
50
57
  end
51
58
 
52
59
  def listen
53
60
  loop do
54
- break unless running?
55
-
56
- with_polling_volume { broadcast_messages }
61
+ begin
62
+ instance = interruptible { Rails.application.executor.run! }
63
+ with_polling_volume { broadcast_messages }
64
+ ensure
65
+ instance.complete! if instance
66
+ end
57
67
 
58
- interruptible_sleep ::SolidCable.polling_interval
68
+ interruptible { sleep ::SolidCable.polling_interval }
59
69
  end
70
+ rescue Stop
71
+ ensure
72
+ @critical.release
60
73
  end
61
74
 
62
- def shutdown
63
- self.running = false
64
- wake_up
75
+ def interruptible
76
+ @critical.release
77
+ yield
78
+ ensure
79
+ @critical.acquire
80
+ end
65
81
 
66
- ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
67
- thread&.join
68
- end
82
+ def shutdown
83
+ @critical.acquire
84
+ # We have the critical permit, and so the listen thread must be
85
+ # safe to interrupt.
86
+ thread.raise(Stop)
87
+ @critical.release
88
+ thread.join
69
89
  end
70
90
 
71
91
  def add_channel(channel, on_success)
@@ -83,15 +103,7 @@ module ActionCable
83
103
 
84
104
  private
85
105
  attr_reader :event_loop, :thread
86
- attr_writer :running, :last_id
87
-
88
- def running?
89
- if defined?(@running)
90
- @running
91
- else
92
- self.running = true
93
- end
94
- end
106
+ attr_writer :last_id
95
107
 
96
108
  def last_id
97
109
  @last_id ||= ::SolidCable::Message.maximum(:id) || 0
@@ -102,12 +114,10 @@ module ActionCable
102
114
  end
103
115
 
104
116
  def broadcast_messages
105
- Rails.application.executor.wrap do
106
- ::SolidCable::Message.broadcastable(channels, last_id).
107
- each do |message|
108
- broadcast(message.channel, message.payload)
109
- self.last_id = message.id
110
- end
117
+ ::SolidCable::Message.broadcastable(channels, last_id).
118
+ each do |message|
119
+ broadcast(message.channel, message.payload)
120
+ self.last_id = message.id
111
121
  end
112
122
  end
113
123
 
@@ -5,6 +5,6 @@ class SolidCable::InstallGenerator < Rails::Generators::Base
5
5
 
6
6
  def copy_files
7
7
  template "db/cable_schema.rb"
8
- template "config/cable.yml", force: true
8
+ template "config/cable.yml"
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCable
4
- VERSION = "3.0.5"
4
+ VERSION = "3.0.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Pezza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-17 00:00:00.000000000 Z
11
+ date: 2025-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord