Class: RhinoThread

Inherits:
Object
  • Object
show all
Defined in:
lib/rhinothread.rb

Instance Method Summary collapse

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

#executeObject

Run everything -:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:



28
29
30
31
32
# File 'lib/rhinothread.rb', line 28

def execute

  StartThreads()

end

#JoinThreadsObject

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

#NewThreadObject

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

#StartThreadsObject

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