Class: Tobox::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/tobox/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Application

Returns a new instance of Application.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tobox/application.rb', line 5

def initialize(configuration)
  @configuration = configuration
  @running = false

  @on_start_handlers = Array(configuration.lifecycle_events[:on_start])
  @on_stop_handlers = Array(configuration.lifecycle_events[:on_stop])

  worker = configuration[:worker]

  @pool = case worker
          when :thread then ThreadedPool
          when :fiber then FiberPool
          else worker
          end.new(configuration)
end

Instance Method Details

#startObject



21
22
23
24
25
26
27
28
# File 'lib/tobox/application.rb', line 21

def start
  return if @running

  @on_start_handlers.each(&:call)

  @pool.start
  @running = true
end

#stopObject



30
31
32
33
34
35
36
37
38
# File 'lib/tobox/application.rb', line 30

def stop
  return unless @running

  @on_stop_handlers.each(&:call)

  @pool.stop

  @running = false
end