Class: Queue

Inherits:
Object show all
Defined in:
lib/backports/2.3.0/queue/close.rb

Constant Summary collapse

CLOSE_MESSAGE =
Object.new

Instance Method Summary collapse

Instance Method Details

#closeObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/backports/2.3.0/queue/close.rb', line 33

def close
  @closed = true
  2.times do
    Thread.pass
    num_waiting.times do
      push_without_close CLOSE_MESSAGE
    end
  end
  self
end

#closed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/backports/2.3.0/queue/close.rb', line 44

def closed?
  !!defined?(@closed)
end

#pop_with_close(non_block = false) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/backports/2.3.0/queue/close.rb', line 19

def pop_with_close(non_block = false)
  begin
    r = pop_without_close(non_block || closed?)

    r unless CLOSE_MESSAGE == r
  rescue ThreadError
    raise if non_block || !closed?
  end
end

#push_with_close(arg) ⇒ Object

Raises:



10
11
12
13
14
# File 'lib/backports/2.3.0/queue/close.rb', line 10

def push_with_close(arg)
  raise ClosedQueueError, 'queue closed' if closed?

  push_without_close(arg)
end