Class: Bridgetown::Container

Inherits:
Async::Container::Forked
  • Object
show all
Defined in:
bridgetown-core/lib/bridgetown-core/container.rb

Defined Under Namespace

Classes: Interceptor, Policy

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Container

Returns a new instance of Container.



8
9
10
11
12
# File 'bridgetown-core/lib/bridgetown-core/container.rb', line 8

def initialize(**options)
  @routines = {}

  super(policy: Policy.new, **options)
end

Instance Method Details

#add_routine(routine) ⇒ Object



14
15
16
# File 'bridgetown-core/lib/bridgetown-core/container.rb', line 14

def add_routine(routine)
  @routines[routine.key] = routine
end

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'bridgetown-core/lib/bridgetown-core/container.rb', line 18

def run
  Process.setproctitle(
    "Bridgetown #{Bridgetown::VERSION} " \
    "— Parent Container [#{File.basename(Dir.pwd)}]"
  )

  @routines.each do |key, routine|
    interceptor = nil
    interceptor = Interceptor.with_tag(routine.tag[:value], color: routine.tag[:color]) \
      if routine.respond_to?(:tag)

    spawn(name: routine.name, key: key) do |instance|
      interceptor&.hook

      routine.execute(instance)
    end
  end
end