File tree 1 file changed +40
-3
lines changed
lib/action_cable/subscription_adapter
1 file changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -50,16 +50,22 @@ def initialize(event_loop)
50
50
end
51
51
52
52
def listen
53
- while running?
53
+ loop do
54
+ break unless running?
55
+
54
56
with_polling_volume { broadcast_messages }
55
57
56
- sleep ::SolidCable . polling_interval
58
+ interruptible_sleep ::SolidCable . polling_interval
57
59
end
58
60
end
59
61
60
62
def shutdown
61
63
self . running = false
62
- Thread . pass while thread . alive?
64
+ wake_up
65
+
66
+ ActiveSupport ::Dependencies . interlock . permit_concurrent_loads do
67
+ thread &.join
68
+ end
63
69
end
64
70
65
71
def add_channel ( channel , on_success )
@@ -112,6 +118,37 @@ def with_polling_volume
112
118
yield
113
119
end
114
120
end
121
+
122
+ def wake_up
123
+ interrupt
124
+ end
125
+
126
+ SELF_PIPE_BLOCK_SIZE = 11
127
+
128
+ def interrupt
129
+ self_pipe [ :writer ] . write_nonblock ( "." )
130
+ rescue Errno ::EAGAIN , Errno ::EINTR
131
+ # Ignore writes that would block and retry
132
+ # if another signal arrived while writing
133
+ retry
134
+ end
135
+
136
+ def interruptible_sleep ( time )
137
+ if time > 0 && self_pipe [ :reader ] . wait_readable ( time )
138
+ loop { self_pipe [ :reader ] . read_nonblock ( SELF_PIPE_BLOCK_SIZE ) }
139
+ end
140
+ rescue Errno ::EAGAIN , Errno ::EINTR
141
+ end
142
+
143
+ # Self-pipe for signal-handling (http://cr.yp.to/docs/selfpipe.html)
144
+ def self_pipe
145
+ @self_pipe ||= create_self_pipe
146
+ end
147
+
148
+ def create_self_pipe
149
+ reader , writer = IO . pipe
150
+ { reader : reader , writer : writer }
151
+ end
115
152
end
116
153
end
117
154
end
You can’t perform that action at this time.
0 commit comments