Class: IRC::Job
- Inherits:
-
Object
- Object
- IRC::Job
- Defined in:
- lib/irc/job.rb
Class Attribute Summary collapse
-
.safe_mode ⇒ Object
Returns the value of attribute safe_mode.
Class Method Summary collapse
- .jobs ⇒ Object
- .run! ⇒ Object
- .schedule(*args, &block) ⇒ Object
-
.shutdown ⇒ Object
def run!.
- .size ⇒ Object
- .size=(_size) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(*args, &block) ⇒ Job
constructor
A new instance of Job.
Constructor Details
#initialize(*args, &block) ⇒ Job
Returns a new instance of Job.
5 6 7 |
# File 'lib/irc/job.rb', line 5 def initialize *args, &block @args, @block = args, block end |
Class Attribute Details
.safe_mode ⇒ Object
Returns the value of attribute safe_mode.
14 15 16 |
# File 'lib/irc/job.rb', line 14 def safe_mode @safe_mode end |
Class Method Details
.jobs ⇒ Object
31 32 33 |
# File 'lib/irc/job.rb', line 31 def jobs @jobs ||= Queue.new end |
.run! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/irc/job.rb', line 35 def run! @pool ||= Array.new(size) do |i| Thread.new do catch :exit do loop do jobs.pop.call end end end end end |
.schedule(*args, &block) ⇒ Object
15 16 17 18 |
# File 'lib/irc/job.rb', line 15 def schedule *args, &block run! jobs << new(*args, &block) end |
.shutdown ⇒ Object
def run!
47 48 49 50 51 |
# File 'lib/irc/job.rb', line 47 def shutdown size.times do schedule { throw :exit } end end |
.size ⇒ Object
20 21 22 |
# File 'lib/irc/job.rb', line 20 def size @size ||= 1 end |
.size=(_size) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/irc/job.rb', line 24 def size= _size _size = _size.to_i _size = 1 if _size < 1 @size = _size end |
Instance Method Details
#call ⇒ Object
9 10 11 |
# File 'lib/irc/job.rb', line 9 def call @block.call(*@args) end |