class Concurrent::Cancellation::Token

Created through {Cancellation.create}, passed down to tasks to be able to check if canceled.

Public Class Methods

new(cancel) click to toggle source
# File lib-edge/concurrent/edge/cancellation.rb, line 131
def initialize(cancel)
  @Cancel = cancel
end

Public Instance Methods

canceled?() click to toggle source

Is the token cancelled? @return [true, false]

# File lib-edge/concurrent/edge/cancellation.rb, line 89
def canceled?
  @Cancel.resolved?
end
inspect()
Alias for: to_s
join(*tokens, &block) click to toggle source

Creates a new token which is cancelled when any of the tokens is. @param [Token] tokens to combine @return [Token] new token

# File lib-edge/concurrent/edge/cancellation.rb, line 116
def join(*tokens, &block)
  block ||= -> token_list { Promises.any_event(*token_list.map(&:to_event)) }
  self.class.new block.call([@Cancel, *tokens])
end
loop_until_canceled(&block) click to toggle source

Repeatedly evaluates block until the token is {#canceled?}. @yield to the block repeatedly. @yieldreturn [Object] @return [Object] last result of the block

# File lib-edge/concurrent/edge/cancellation.rb, line 97
def loop_until_canceled(&block)
  until canceled?
    result = block.call
  end
  result
end
raise_if_canceled(error = CancelledOperationError) click to toggle source

Raise error when cancelled @param [#exception] error to be risen @raise the error @return [self]

# File lib-edge/concurrent/edge/cancellation.rb, line 108
def raise_if_canceled(error = CancelledOperationError)
  raise error if canceled?
  self
end
to_event() click to toggle source

@return [Event] Event which will be resolved when the token is cancelled.

# File lib-edge/concurrent/edge/cancellation.rb, line 77
def to_event
  @Cancel.to_event
end
to_future() click to toggle source

@return [Future] Future which will be resolved when the token is cancelled with arguments passed in

{Cancellation.create} .
# File lib-edge/concurrent/edge/cancellation.rb, line 83
def to_future
  @Cancel.to_future
end
to_s() click to toggle source

Short string representation. @return [String]

Calls superclass method
# File lib-edge/concurrent/edge/cancellation.rb, line 123
def to_s
  format '%s canceled:%s>', super[0..-2], canceled?
end
Also aliased as: inspect