Class: Rbgo::Channel::BufferChan
- Inherits:
-
SizedQueue
- Object
- SizedQueue
- Rbgo::Channel::BufferChan
- Includes:
- Enumerable, Chan
- Defined in:
- lib/rbgo/select_chan.rb
Overview
BufferChan
Instance Method Summary collapse
- #clear ⇒ Object
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(max) ⇒ BufferChan
constructor
A new instance of BufferChan.
- #pop(nonblock = false) ⇒ Object (also: #deq, #shift)
- #push(obj, nonblock = false) ⇒ Object (also: #<<, #enq)
Methods included from Chan
Constructor Details
#initialize(max) ⇒ BufferChan
Returns a new instance of BufferChan.
202 203 204 205 206 207 208 |
# File 'lib/rbgo/select_chan.rb', line 202 def initialize(max) super(max) @mutex = Mutex.new self.ios = [] self.register_mutex = Mutex.new end |
Instance Method Details
#clear ⇒ Object
235 236 237 238 239 |
# File 'lib/rbgo/select_chan.rb', line 235 def clear super notify self end |
#close ⇒ Object
241 242 243 244 245 246 247 |
# File 'lib/rbgo/select_chan.rb', line 241 def close @mutex.synchronize do super notify self end end |
#each ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rbgo/select_chan.rb', line 188 def each if block_given? loop do begin yield pop(true) rescue ThreadError return end end else enum_for(:each) end end |
#pop(nonblock = false) ⇒ Object Also known as: deq, shift
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/rbgo/select_chan.rb', line 219 def pop(nonblock = false) @mutex.synchronize do res = nil ok = true ok = false if empty? && closed? begin res = super(nonblock) notify rescue ThreadError raise unless closed? ok = false end [res, ok] end end |
#push(obj, nonblock = false) ⇒ Object Also known as: <<, enq
210 211 212 213 214 215 216 217 |
# File 'lib/rbgo/select_chan.rb', line 210 def push(obj, nonblock = false) super(obj, nonblock) notify self rescue ThreadError raise ClosedQueueError.new if closed? raise end |