Class: Prosody::CancellationToken
- Inherits:
-
Object
- Object
- Prosody::CancellationToken
- Defined in:
- lib/prosody/processor.rb,
sig/processor.rbs
Overview
Provides a mechanism for canceling asynchronous tasks
Instance Method Summary collapse
-
#cancel ⇒ void
Signals that the associated task should be canceled Wakes up any threads waiting on #wait.
-
#initialize ⇒ CancellationToken
constructor
Creates a new token with an internal queue for signaling.
-
#wait ⇒ Object
Blocks until cancellation is requested.
Constructor Details
#initialize ⇒ CancellationToken
Creates a new token with an internal queue for signaling
16 17 18 |
# File 'lib/prosody/processor.rb', line 16 def initialize @queue = Queue.new end |
Instance Method Details
#cancel ⇒ void
This method returns an undefined value.
Signals that the associated task should be canceled Wakes up any threads waiting on #wait
24 25 26 |
# File 'lib/prosody/processor.rb', line 24 def cancel @queue.push(:cancel) end |
#wait ⇒ Object
Blocks until cancellation is requested
34 35 36 37 |
# File 'lib/prosody/processor.rb', line 34 def wait @queue.pop true end |