Class: Celluloid::Future
- Defined in:
- lib/vendor/celluloid/lib/celluloid/future.rb
Overview
Celluloid::Future objects allow methods and blocks to run in the background, their values requested later
Defined Under Namespace
Classes: Runner
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Future
constructor
Create a new Celluloid::Future object, allowing a block to be computed in the background and its return value obtained later.
-
#value ⇒ Object
(also: #call)
Obtain the value for this Future.
Constructor Details
#initialize(*args, &block) ⇒ Future
Create a new Celluloid::Future object, allowing a block to be computed in the background and its return value obtained later
9 10 11 12 13 14 15 |
# File 'lib/vendor/celluloid/lib/celluloid/future.rb', line 9 def initialize(*args, &block) @lock = Mutex.new @value_obtained = false @runner = Runner.new(*args, &block) @runner.run! end |
Instance Method Details
#value ⇒ Object Also known as: call
Obtain the value for this Future
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/celluloid/lib/celluloid/future.rb', line 18 def value @lock.synchronize do unless @value_obtained @value = @runner.value @runner.terminate @value_obtained = true end @value end end |