module GBDispatch

Library to dispatch block on queues. It is inspired by GCD but implementation is based on Celluloid. Current implementation ensure that block on queue will be executed in the same order as added, however it doesn't ensure on which thread it will run.

Threading

Each queue have it is own thread, but their only for synchronisation. All execution happens on runners thread pool. Pool size is limited to number of cores of the machine.

Queue manager for simulating Grand Central Dispatch behaviour.

It is singleton class, so all calls should be invoked through GBDispatch::Manager.instance

Constants

VERSION

Public Class Methods

dispatch_after(delay, queue) { || ... } click to toggle source

Dispatch on queue with delay. @param delay [Fixnum, Float] delay in seconds @param queue [Symbol, GBDispatch::Queue] queue object or name @yield block to execute

# File lib/gb_dispatch.rb, line 48
def self.dispatch_after(delay, queue)
  queue = get_queue(queue) unless queue.is_a? GBDispatch::Queue
  GBDispatch::Manager.instance.run_after_on_queue delay, queue do
    yield
  end
end
Also aliased as: dispatch_after_on_queue
dispatch_after_on_queue(delay, queue)
Alias for: dispatch_after
dispatch_async(queue) { || ... } click to toggle source

Dispatch asynchronously on queue @param queue [Symbol, GBDispatch::Queue] queue object or name @yield block to execute

# File lib/gb_dispatch.rb, line 26
def self.dispatch_async(queue)
  queue = get_queue(queue) unless queue.is_a? GBDispatch::Queue
  GBDispatch::Manager.instance.run_async_on_queue queue do
    yield
  end
end
Also aliased as: dispatch_async_on_queue
dispatch_async_on_queue(queue)
Alias for: dispatch_async
dispatch_sync(queue) { || ... } click to toggle source

Dispatch synchronously on queue and return result @param queue [Symbol, GBDispatch::Queue] queue object or name @yield block to execute

# File lib/gb_dispatch.rb, line 36
def self.dispatch_sync(queue)
  queue = get_queue(queue) unless queue.is_a? GBDispatch::Queue
  GBDispatch::Manager.instance.run_sync_on_queue queue do
    yield
  end
end
Also aliased as: dispatch_sync_on_queue
dispatch_sync_on_queue(queue)
Alias for: dispatch_sync
get_queue(name) click to toggle source

Get queue of given name @return [GBDispatch:Queue] @param name [#to_sym]

# File lib/gb_dispatch.rb, line 19
def self.get_queue(name)
  GBDispatch::Manager.instance.get_queue(name)
end
logger() click to toggle source
# File lib/gb_dispatch.rb, line 62
def self.logger
  @logger ||= Logger.new(STDOUT)
end
logger=(logger) click to toggle source

Setup logger. By default it use Celluloid logger @param logger [Logger]

# File lib/gb_dispatch.rb, line 58
def self.logger=(logger)
  @logger = logger
end