Class: Core::Async::Filament

Inherits:
Object
  • Object
show all
Includes:
Is::Inspectable
Defined in:
lib/core/async/filament.rb

Overview

Internal object that wraps a fiber.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFilament

Returns a new instance of Filament.



15
16
17
18
19
20
21
# File 'lib/core/async/filament.rb', line 15

def initialize
  @object = nil
  @channel = nil
  @children = nil
  @resolved = false
  @value = nil
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



24
25
26
# File 'lib/core/async/filament.rb', line 24

def children
  @children
end

#objectObject

Returns the value of attribute object.



23
24
25
# File 'lib/core/async/filament.rb', line 23

def object
  @object
end

Instance Method Details

#add_child(fiber) ⇒ Object



26
27
28
# File 'lib/core/async/filament.rb', line 26

def add_child(fiber)
  (@children ||= []) << fiber
end

#resolve(value = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/core/async/filament.rb', line 30

def resolve(value = nil)
  unless @resolved
    @value = value
    @resolved = true
    @channel&.publish(value)
  end
end

#waitObject



38
39
40
41
42
43
44
# File 'lib/core/async/filament.rb', line 38

def wait
  if @resolved == false && @object&.alive?
    (@channel ||= Channel.new).subscribe
  else
    @value
  end
end