Sha256: 1a83c249546ef3b7edf7b28c1a470a4b2278a6fbfd784cd14f370959af9a3162

Contents?: true

Size: 801 Bytes

Versions: 12

Compression:

Stored size: 801 Bytes

Contents

# frozen_string_literal: true

module Tobox
  class Application
    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

    def start
      return if @running

      @on_start_handlers.each(&:call)

      @pool.start
      @running = true
    end

    def stop
      return unless @running

      @on_stop_handlers.each(&:call)

      @pool.stop

      @running = false
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
tobox-0.7.0 lib/tobox/application.rb
tobox-0.6.1 lib/tobox/application.rb
tobox-0.6.0 lib/tobox/application.rb
tobox-0.5.2 lib/tobox/application.rb
tobox-0.5.1 lib/tobox/application.rb
tobox-0.5.0 lib/tobox/application.rb
tobox-0.4.5 lib/tobox/application.rb
tobox-0.4.4 lib/tobox/application.rb
tobox-0.4.3 lib/tobox/application.rb
tobox-0.4.2 lib/tobox/application.rb
tobox-0.4.1 lib/tobox/application.rb
tobox-0.4.0 lib/tobox/application.rb