lib/sideband.rb in sideband-1.0.1 vs lib/sideband.rb in sideband-1.0.2
- old
+ new
@@ -5,15 +5,12 @@
require 'sideband/thread'
require 'sideband/worker'
module Sideband
- class NotInitializedError < Exception; end
-
def self.initialize!
new_manager = Manager.new
- puts 'Sideband initialized!'
if block_given?
begin
::Thread.current['sideband.manager'] = new_manager
yield
@@ -33,16 +30,24 @@
def self.kill
manager.kill
::Thread.current['sideband.manager'] = nil
end
- def self.queue
- manager.queue
+ def self.queue(job = nil)
+ if job
+ manager.queue << job
+ else
+ manager.queue
+ end
end
+ def self.enqueue(job = nil)
+ queue(job)
+ end
+
def self.manager
manager = ::Thread.current['sideband.manager']
- raise NotInitializedError.new('Sideband must be initialized! before using.') if manager.nil?
+ manager = initialize! if manager.nil?
manager
end
end