Class: Heimdall::Que

Inherits:
Object show all
Defined in:
lib/heimdall/heimdall_que.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#activeObject (readonly)

Returns the value of attribute active.



5
6
7
# File 'lib/heimdall/heimdall_que.rb', line 5

def active
  @active
end

#sizeObject (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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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