Class: FutureProof::Future
- Inherits:
-
Object
- Object
- FutureProof::Future
- Defined in:
- lib/future_proof/future.rb
Overview
Class Futures can be used to create Procs that should be executed inside a Thread.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Executes
Futurein a thread with given params. -
#complete? ⇒ true, false
Return true if
Futureis done working. -
#initialize(&block) ⇒ Future
constructor
Initializes new
Future. -
#value(*args) ⇒ Object
Return a result of a
Future.
Constructor Details
#initialize(&block) ⇒ Future
Initializes new Future.
11 12 13 |
# File 'lib/future_proof/future.rb', line 11 def initialize(&block) @block = block end |
Instance Method Details
#call(*args) ⇒ Object
Executes Future in a thread with given params.
21 22 23 |
# File 'lib/future_proof/future.rb', line 21 def call(*args) thread(*args) end |
#complete? ⇒ true, false
Return true if Future is done working.
43 44 45 |
# File 'lib/future_proof/future.rb', line 43 def complete? !thread.alive? end |
#value(*args) ⇒ Object
Note:
It requires list of arguments if Future was not called before.
Return a result of a Future.
33 34 35 |
# File 'lib/future_proof/future.rb', line 33 def value(*args) thread(*args).value end |