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.

[View source]

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

def initialize
  clear
end

Instance Method Details

#clearObject

[View source]

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

def clear
  @storage = []
end

#each(&block) ⇒ Object

[View source]

110
111
112
# File 'opal/stdlib/thread.rb', line 110

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

#empty?Boolean

Returns:

[View source]

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

def empty?
  @storage.empty?
end

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

[View source]

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

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

[View source]

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

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

#sizeObject Also known as: length

[View source]

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

def size
  @storage.size
end