Class: Thread::Queue

Inherits:
Object show all
Defined in:
opal/stdlib/thread.rb

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.



73
74
75
# File 'opal/stdlib/thread.rb', line 73

def initialize
  clear
end

Instance Method Details

#clearObject



77
78
79
# File 'opal/stdlib/thread.rb', line 77

def clear
  @storage = []
end

#each(&block) ⇒ Object



102
103
104
# File 'opal/stdlib/thread.rb', line 102

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

#empty?Boolean

Returns:



81
82
83
# File 'opal/stdlib/thread.rb', line 81

def empty?
  @storage.empty?
end

#pop(non_block = false) ⇒ Object Also known as: deq, shift



89
90
91
92
93
94
95
96
# File 'opal/stdlib/thread.rb', line 89

def pop(non_block = false)
  if empty?
    raise ThreadError, 'Queue empty' if non_block
    raise ThreadError, 'Deadlock'
  end

  @storage.shift
end

#push(value) ⇒ Object Also known as: <<, enq



98
99
100
# File 'opal/stdlib/thread.rb', line 98

def push(value)
  @storage.push(value)
end

#sizeObject Also known as: length



85
86
87
# File 'opal/stdlib/thread.rb', line 85

def size
  @storage.size
end