Class: Heimdall::Que
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#add(&block) ⇒ Object
add to block, it is possible to add.
-
#done? ⇒ Boolean
are the all jobs done?.
-
#has_free? ⇒ Boolean
does it have a free slot?.
-
#initialize(size = 5) ⇒ Que
constructor
A new instance of Que.
- #status_text(i) ⇒ Object
Constructor Details
#initialize(size = 5) ⇒ Que
Returns a new instance of Que.
7 8 9 10 |
# File 'lib/heimdall/heimdall_que.rb', line 7 def initialize size = 5 @size = size @active = [] end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
5 6 7 |
# File 'lib/heimdall/heimdall_que.rb', line 5 def active @active end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/heimdall/heimdall_que.rb', line 5 def size @size end |
Instance Method Details
#add(&block) ⇒ Object
add to block, it is possible to add
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/heimdall/heimdall_que.rb', line 13 def add &block in_ques do |i| if is_free?(i) @active[i] = Thread.new(&block) return true end end false end |
#done? ⇒ Boolean
are the all jobs done?
34 35 36 37 38 39 40 |
# File 'lib/heimdall/heimdall_que.rb', line 34 def done? in_ques do |i| return false unless is_free?(i) end true end |
#has_free? ⇒ Boolean
does it have a free slot?
25 26 27 28 29 30 31 |
# File 'lib/heimdall/heimdall_que.rb', line 25 def has_free? in_ques do |i| return true if is_free?(i) end false end |
#status_text(i) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/heimdall/heimdall_que.rb', line 42 def status_text i if @active[i] status = @active[i].status if status.class == String 'Active (%s)' % status else 'Free' end else 'Free' end end |