Class: LightIO::Core::Future
- Inherits:
-
Object
- Object
- LightIO::Core::Future
- Defined in:
- lib/lightio/core/future.rb
Overview
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize ⇒ Future
constructor
A new instance of Future.
-
#transfer(value = nil) ⇒ Object
Transfer and set result value.
-
#value ⇒ Object
Get value.
- #value=(value) ⇒ Object
Constructor Details
Instance Method Details
#done? ⇒ Boolean
18 19 20 |
# File 'lib/lightio/core/future.rb', line 18 def done? @state == :done end |
#transfer(value = nil) ⇒ Object
Transfer and set result value
use this method to set back result
25 26 27 28 29 30 |
# File 'lib/lightio/core/future.rb', line 25 def transfer(value=nil) raise LightIO::Error, "state error" if done? @value = value done! @light_fiber.transfer if @light_fiber end |
#value ⇒ Object
Get value
this method will block current beam/fiber, until future result is set.
39 40 41 42 43 44 45 |
# File 'lib/lightio/core/future.rb', line 39 def value return @value if done? raise LightIO::Error, 'already used' if @light_fiber @light_fiber = LightFiber.current @ioloop.transfer @value end |
#value=(value) ⇒ Object
32 33 34 |
# File 'lib/lightio/core/future.rb', line 32 def value=(value) transfer(value) end |