Class: RhinoThread
- Inherits:
-
Object
- Object
- RhinoThread
- Defined in:
- lib/rhinothread.rb
Instance Method Summary collapse
-
#execute ⇒ Object
Run everything -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:.
-
#initialize(limit) ⇒ RhinoThread
constructor
New Instance -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:.
-
#JoinThreads ⇒ Object
Join Threads -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:.
-
#NewThread ⇒ Object
Execute each thread -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:.
-
#queue(&block) ⇒ Object
Store a block of code -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:.
-
#StartThreads ⇒ Object
Start the first(@limit) threads -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:.
Constructor Details
#initialize(limit) ⇒ RhinoThread
New Instance -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
5 6 7 8 9 10 11 12 |
# File 'lib/rhinothread.rb', line 5 def initialize limit @threads = [] @queue = [] @on = true @limit = limit end |
Instance Method Details
#execute ⇒ Object
Run everything -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
28 29 30 31 32 |
# File 'lib/rhinothread.rb', line 28 def execute StartThreads() end |
#JoinThreads ⇒ Object
Join Threads -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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 ⇒ Object
Execute each thread -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rhinothread.rb', line 72 def NewThread() tCount = @threads.count @threads << Thread.new(tCount) do |tNum| @queue[tNum].call Thread.exit end end |
#queue(&block) ⇒ Object
Store a block of code -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
18 19 20 21 22 |
# File 'lib/rhinothread.rb', line 18 def queue &block @queue << block end |
#StartThreads ⇒ Object
Start the first(@limit) threads -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rhinothread.rb', line 38 def StartThreads() @limit = @queue.count if @limit >= @queue.count @limit.times do |i| NewThread() end JoinThreads() end |