class RhinoThread
Public Class Methods
new(limit)
click to toggle source
New Instance -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# File lib/rhinothread.rb, line 5 def initialize limit @threads = [] @queue = [] @on = true @limit = limit end
Public Instance Methods
JoinThreads()
click to toggle source
Join Threads -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# File lib/rhinothread.rb, line 54 def JoinThreads() @threads.each do |aThread| if aThread.join NewThread() if @threads.count < @queue.count && @on end end end
NewThread()
click to toggle source
Execute each thread -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# File lib/rhinothread.rb, line 72 def NewThread() tCount = @threads.count @threads << Thread.new(tCount) do |tNum| @queue[tNum].call Thread.exit end end
StartThreads()
click to toggle source
Start the first(@limit) threads -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# File lib/rhinothread.rb, line 38 def StartThreads() @limit = @queue.count if @limit >= @queue.count @limit.times do |i| NewThread() end JoinThreads() end
execute()
click to toggle source
Run everything -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# File lib/rhinothread.rb, line 28 def execute StartThreads() end
queue(&block)
click to toggle source
Store a block of code -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
# File lib/rhinothread.rb, line 18 def queue &block @queue << block end