Class: Cadenya::Core::CancelHandle
- Inherits:
-
Object
- Object
- Cadenya::Core::CancelHandle
- Defined in:
- lib/cadenya/core.rb
Overview
Cancellation handle for a streaming request. cancel! from any thread
tears the transport down, which unblocks a read parked on a silent
socket — polling a flag between chunks cannot do that.
Instance Method Summary collapse
- #attach(&teardown) ⇒ Object
- #cancel! ⇒ Object
- #cancelled? ⇒ Boolean
-
#initialize ⇒ CancelHandle
constructor
A new instance of CancelHandle.
Constructor Details
#initialize ⇒ CancelHandle
Returns a new instance of CancelHandle.
240 241 242 243 244 |
# File 'lib/cadenya/core.rb', line 240 def initialize @mutex = Mutex.new @cancelled = false @teardown = nil end |
Instance Method Details
#attach(&teardown) ⇒ Object
246 247 248 249 250 251 252 253 |
# File 'lib/cadenya/core.rb', line 246 def attach(&teardown) fire = @mutex.synchronize do @teardown = teardown @cancelled end safe_call(teardown) if fire nil end |
#cancel! ⇒ Object
255 256 257 258 259 260 261 262 |
# File 'lib/cadenya/core.rb', line 255 def cancel! teardown = @mutex.synchronize do @cancelled = true @teardown end safe_call(teardown) nil end |
#cancelled? ⇒ Boolean
264 265 266 |
# File 'lib/cadenya/core.rb', line 264 def cancelled? @mutex.synchronize { @cancelled } end |