Class: Concurrent::Cancellation
- Inherits:
-
Synchronization::Object
- Object
- Synchronization::Object
- Concurrent::Cancellation
- Defined in:
- lib/concurrent/edge/cancellation.rb
Overview
Provides tools for cooperative cancellation. Inspired by msdn.microsoft.com/en-us/library/dd537607(v=vs.110).aspx
Defined Under Namespace
Classes: Token
Class Method Summary collapse
-
.create(resolvable_future_or_event = Promises.resolvable_event, *resolve_args) ⇒ Array(Cancellation, Cancellation::Token)
Creates the cancellation object.
Instance Method Summary collapse
-
#cancel(raise_on_repeated_call = true) ⇒ true, false
Cancel this cancellation.
-
#canceled? ⇒ true, false
Is the cancellation cancelled?.
-
#to_s ⇒ String
(also: #inspect)
Short string representation.
-
#token ⇒ Token
Returns the token associated with the cancellation.
Class Method Details
.create(resolvable_future_or_event = Promises.resolvable_event, *resolve_args) ⇒ Array(Cancellation, Cancellation::Token)
Creates the cancellation object. Returns both the cancellation and the token for convenience.
27 28 29 30 |
# File 'lib/concurrent/edge/cancellation.rb', line 27 def self.create(resolvable_future_or_event = Promises.resolvable_event, *resolve_args) cancellation = new(resolvable_future_or_event, *resolve_args) [cancellation, cancellation.token] end |
Instance Method Details
#cancel(raise_on_repeated_call = true) ⇒ true, false
Cancel this cancellation. All executions depending on the token will cooperatively stop.
43 44 45 |
# File 'lib/concurrent/edge/cancellation.rb', line 43 def cancel(raise_on_repeated_call = true) !!@Cancel.resolve(*@ResolveArgs, raise_on_repeated_call) end |
#canceled? ⇒ true, false
Is the cancellation cancelled?
49 50 51 |
# File 'lib/concurrent/edge/cancellation.rb', line 49 def canceled? @Cancel.resolved? end |
#to_s ⇒ String Also known as: inspect
Short string representation.
55 56 57 |
# File 'lib/concurrent/edge/cancellation.rb', line 55 def to_s format '<#%s:0x%x canceled:%s>', self.class, object_id << 1, canceled? end |
#token ⇒ Token
Returns the token associated with the cancellation.
36 37 38 |
# File 'lib/concurrent/edge/cancellation.rb', line 36 def token @Token end |