Class: Bricolage::TaskQueue

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

Direct Known Subclasses

FileTaskQueue

Instance Method Summary collapse

Constructor Details

#initializeTaskQueue

Returns a new instance of TaskQueue.



9
10
11
# File 'lib/bricolage/taskqueue.rb', line 9

def initialize
  @queue = []
end

Instance Method Details

#consume_eachObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/bricolage/taskqueue.rb', line 29

def consume_each
  lock
  save
  while task = self.next
    yield task
    deq
  end
ensure
  unlock
end

#deqObject



48
49
50
51
52
# File 'lib/bricolage/taskqueue.rb', line 48

def deq
  task = @queue.shift
  save
  task
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/bricolage/taskqueue.rb', line 25

def each(&block)
  @queue.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/bricolage/taskqueue.rb', line 13

def empty?
  @queue.empty?
end

#enq(task) ⇒ Object



40
41
42
# File 'lib/bricolage/taskqueue.rb', line 40

def enq(task)
  @queue.push task
end

#lockObject



64
65
# File 'lib/bricolage/taskqueue.rb', line 64

def lock
end

#locked?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/bricolage/taskqueue.rb', line 60

def locked?
  false
end

#nextObject



44
45
46
# File 'lib/bricolage/taskqueue.rb', line 44

def next
  @queue.first
end

#queued?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/bricolage/taskqueue.rb', line 21

def queued?
  not empty?
end

#restoreObject



57
58
# File 'lib/bricolage/taskqueue.rb', line 57

def restore
end

#saveObject



54
55
# File 'lib/bricolage/taskqueue.rb', line 54

def save
end

#sizeObject



17
18
19
# File 'lib/bricolage/taskqueue.rb', line 17

def size
  @queue.size
end

#unlockObject



67
68
# File 'lib/bricolage/taskqueue.rb', line 67

def unlock
end

#unlock_helpObject



70
71
72
# File 'lib/bricolage/taskqueue.rb', line 70

def unlock_help
  "[MUST NOT HAPPEN] this message must not be shown"
end