Sha256: 2cec85a6736a2dfcde711c1842996ea994090b3519118b660b59c83e993a1ada

Contents?: true

Size: 709 Bytes

Versions: 1

Compression:

Stored size: 709 Bytes

Contents

require 'singleton'
require 'gb_dispatch/runner'
require 'gb_dispatch/queue'
module GBDispatch
  class Manager
    include Singleton

    def get_queue(name=:default)
      queue = Celluloid::Actor[name.to_sym]
      unless queue
        supervisor = Queue.supervise_as name, name, @pool
        queue = supervisor.actors.first
      end
      queue
    end

    # @param queue [GBDispatch::Queue]
    def run_async_on_queue(queue)
      queue.async.perform ->() { yield }
    end

    # @param queue [GBDispatch::Queue]
    def run_sync_on_queue(queue)
      future = queue.future.perform ->() { yield }
      future.value
    end

    private

    def initialize
      @pool = Runner.pool
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gb_dispatch-0.0.1 lib/gb_dispatch/manager.rb