Class: Pwrake::NBIO::FiberReaderQueue
- Inherits:
-
Object
- Object
- Pwrake::NBIO::FiberReaderQueue
- Defined in:
- lib/pwrake/nbio.rb
Overview
Instance Method Summary collapse
- #deq ⇒ Object (also: #get_line)
- #enq(x) ⇒ Object
- #halt ⇒ Object
-
#initialize(reader) ⇒ FiberReaderQueue
constructor
A new instance of FiberReaderQueue.
Constructor Details
#initialize(reader) ⇒ FiberReaderQueue
Returns a new instance of FiberReaderQueue.
415 416 417 418 419 420 |
# File 'lib/pwrake/nbio.rb', line 415 def initialize(reader) @reader = reader @q = [] @waiter = [] @halting = false end |
Instance Method Details
#deq ⇒ Object Also known as: get_line
428 429 430 431 432 433 434 435 |
# File 'lib/pwrake/nbio.rb', line 428 def deq while @q.empty? return nil if @halting @waiter.push(Fiber.current) @reader.select_io end @q.shift end |
#enq(x) ⇒ Object
422 423 424 425 426 |
# File 'lib/pwrake/nbio.rb', line 422 def enq(x) @q.push(x) f = @waiter.shift f.resume if f end |
#halt ⇒ Object
439 440 441 442 443 444 445 446 |
# File 'lib/pwrake/nbio.rb', line 439 def halt @halting = true while f = @waiter.shift f.resume end ensure @halting = false end |