Class: Prosody::CancellationToken

Inherits:
Object
  • Object
show all
Defined in:
lib/prosody/processor.rb,
sig/processor.rbs

Overview

Provides a mechanism for canceling asynchronous tasks

Instance Method Summary collapse

Constructor Details

#initializeCancellationToken

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

#cancelvoid

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

#waitObject

Blocks until cancellation is requested

Returns:

  • always returns true after cancellation is received



34
35
36
37
# File 'lib/prosody/processor.rb', line 34

def wait
  @queue.pop
  true
end