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
17 18 19 |
# File 'lib/lightio/core/future.rb', line 17 def done? @state == :done end |
#transfer(value = nil) ⇒ Object
Transfer and set result value
use this method to set back result
24 25 26 27 28 29 |
# File 'lib/lightio/core/future.rb', line 24 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.
38 39 40 41 42 43 44 |
# File 'lib/lightio/core/future.rb', line 38 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
31 32 33 |
# File 'lib/lightio/core/future.rb', line 31 def value=(value) transfer(value) end |