Class: Ori::Promise
Overview
: [E]
Instance Method Summary collapse
-
#await ⇒ Object
: () -> E.
- #deconstruct ⇒ Object
-
#initialize ⇒ Promise
constructor
A new instance of Promise.
-
#resolve(value) ⇒ Object
: (E value) -> void.
-
#resolved? ⇒ Boolean
: () -> bool.
Constructor Details
#initialize ⇒ Promise
Returns a new instance of Promise.
8 9 10 11 |
# File 'lib/ori/promise.rb', line 8 def initialize @resolved = false @value = nil end |
Instance Method Details
#await ⇒ Object
: () -> E
32 33 34 35 36 37 |
# File 'lib/ori/promise.rb', line 32 def await return @value if resolved? Fiber.yield(self) until resolved? @value end |
#deconstruct ⇒ Object
26 27 28 29 |
# File 'lib/ori/promise.rb', line 26 def deconstruct await unless resolved? [@value] end |
#resolve(value) ⇒ Object
: (E value) -> void
14 15 16 17 18 19 |
# File 'lib/ori/promise.rb', line 14 def resolve(value) raise "Promise already resolved" if resolved? @resolved = true @value = value end |
#resolved? ⇒ Boolean
: () -> bool
22 23 24 |
# File 'lib/ori/promise.rb', line 22 def resolved? @resolved end |