Class: Ori::Promise

Inherits:
Object
  • Object
show all
Includes:
Selectable
Defined in:
lib/ori/promise.rb

Overview

: [E]

Instance Method Summary collapse

Constructor Details

#initializePromise

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

#awaitObject

: () -> 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

#deconstructObject



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

Returns:

  • (Boolean)


22
23
24
# File 'lib/ori/promise.rb', line 22

def resolved?
  @resolved
end