Sha256: a02b3a9ab37cc2327561463ae0137d0bb9419b42765eebebba852a276d8f8a9b

Contents?: true

Size: 788 Bytes

Versions: 11

Compression:

Stored size: 788 Bytes

Contents

# frozen_string_literal: true

require "timeout"
require "fiber_scheduler"

module Tobox
  class FiberPool < Pool
    def initialize(_configuration)
      Sequel.extension(:fiber_concurrency)
      super
    end

    def start
      @fiber_thread = Thread.start do
        Thread.current.name = "tobox-fibers-thread"

        FiberScheduler do
          @workers.each_with_index do |wk, _idx|
            Fiber.schedule { do_work(wk) }
          end
        end
      end
    end

    def stop
      shutdown_timeout = @configuration[:shutdown_timeout]

      super

      begin
        Timeout.timeout(shutdown_timeout) { @fiber_thread.value }
      rescue Timeout::Error
        # hard exit
        @fiber_thread.raise(KillError)
        @fiber_thread.value
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tobox-0.5.0 lib/tobox/pool/fiber_pool.rb
tobox-0.4.5 lib/tobox/pool/fiber_pool.rb
tobox-0.4.4 lib/tobox/pool/fiber_pool.rb
tobox-0.4.3 lib/tobox/pool/fiber_pool.rb
tobox-0.4.2 lib/tobox/pool/fiber_pool.rb
tobox-0.4.1 lib/tobox/pool/fiber_pool.rb
tobox-0.4.0 lib/tobox/pool/fiber_pool.rb
tobox-0.3.2 lib/tobox/pool/fiber_pool.rb
tobox-0.3.1 lib/tobox/pool/fiber_pool.rb
tobox-0.3.0 lib/tobox/pool/fiber_pool.rb
tobox-0.2.0 lib/tobox/pool/fiber_pool.rb