Class: Concurrent::AbstractExchanger
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
|
|
|
Instance Chain:
|
|
| Inherits: |
Concurrent::Synchronization::Object
|
| Defined in: | lib/concurrent-ruby/concurrent/exchanger.rb |
Constant Summary
-
CANCEL =
private
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 41::Object.new
Class Attribute Summary
Synchronization::Object - Inherited
Class Method Summary
- .new ⇒ AbstractExchanger constructor
Synchronization::Object - Inherited
| .atomic_attribute?, .atomic_attributes, | |
| .attr_atomic | Creates methods for reading and writing to a instance variable with volatile (Java) semantic as |
| .attr_volatile | Creates methods for reading and writing (as |
| .ensure_safe_initialization_when_final_fields_are_present | For testing purposes, quite slow. |
| .new | Has to be called by children. |
| .safe_initialization!, .define_initialize_atomic_fields | |
Synchronization::AbstractObject - Inherited
Instance Method Summary
-
#exchange(value, timeout = nil) ⇒ Object
Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return.
-
#exchange!(value, timeout = nil) ⇒ Object
Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return.
-
#try_exchange(value, timeout = nil) ⇒ Concurrent::Maybe
Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return.
-
#do_exchange(value, timeout) ⇒ Object, CANCEL
private
Waits for another thread to arrive at this exchange point (unless the current thread is interrupted), and then transfers the given object to it, receiving its object in return.
Synchronization::Object - Inherited
Synchronization::Volatile - Included
Synchronization::AbstractObject - Inherited
Constructor Details
.new ⇒ AbstractExchanger
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 44
def initialize super end
Instance Method Details
#do_exchange(value, timeout) ⇒ Object, CANCEL (private)
Waits for another thread to arrive at this exchange point (unless the
current thread is interrupted), and then transfers the given object to
it, receiving its object in return. The timeout value indicates the
approximate number of seconds the method should block while waiting
for the exchange. When the timeout value is nil the method will
block indefinitely.
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 122
def do_exchange(value, timeout) raise NotImplementedError end
#exchange(value, timeout = nil) ⇒ Object
Waits for another thread to arrive at this exchange point (unless the
current thread is interrupted), and then transfers the given object to
it, receiving its object in return. The timeout value indicates the
approximate number of seconds the method should block while waiting
for the exchange. When the timeout value is nil the method will
block indefinitely.
In some edge cases when a timeout is given a return value of nil may be
ambiguous. Specifically, if nil is a valid value in the exchange it will
be impossible to tell whether nil is the actual return value or if it
signifies timeout. When nil is a valid value in the exchange consider
using #exchange! or #try_exchange instead.
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 69
def exchange(value, timeout = nil) (value = do_exchange(value, timeout)) == CANCEL ? nil : value end
#exchange!(value, timeout = nil) ⇒ Object
Waits for another thread to arrive at this exchange point (unless the
current thread is interrupted), and then transfers the given object to
it, receiving its object in return. The timeout value indicates the
approximate number of seconds the method should block while waiting
for the exchange. When the timeout value is nil the method will
block indefinitely.
On timeout a TimeoutError exception will be raised.
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 80
def exchange!(value, timeout = nil) if (value = do_exchange(value, timeout)) == CANCEL raise Concurrent::TimeoutError else value end end
#try_exchange(value, timeout = nil) ⇒ Concurrent::Maybe
Waits for another thread to arrive at this exchange point (unless the
current thread is interrupted), and then transfers the given object to
it, receiving its object in return. The timeout value indicates the
approximate number of seconds the method should block while waiting
for the exchange. When the timeout value is nil the method will
block indefinitely.
The return value will be a Maybe set to Just on success or
Nothing on timeout.
# File 'lib/concurrent-ruby/concurrent/exchanger.rb', line 109
def try_exchange(value, timeout = nil) if (value = do_exchange(value, timeout)) == CANCEL Concurrent::Maybe.nothing(Concurrent::TimeoutError) else Concurrent::Maybe.just(value) end end