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.
432 433 434 435 436 437 |
# File 'lib/pwrake/nbio.rb', line 432 def initialize(reader) @reader = reader @q = [] @waiter = [] @halting = false end |
Instance Method Details
#deq ⇒ Object Also known as: get_line
445 446 447 448 449 450 451 452 |
# File 'lib/pwrake/nbio.rb', line 445 def deq while @q.empty? return nil if @halting @waiter.push(Fiber.current) @reader.select_io end @q.shift end |
#enq(x) ⇒ Object
439 440 441 442 443 |
# File 'lib/pwrake/nbio.rb', line 439 def enq(x) @q.push(x) f = @waiter.shift f.resume if f end |
#halt ⇒ Object
456 457 458 459 460 461 462 463 |
# File 'lib/pwrake/nbio.rb', line 456 def halt @halting = true while f = @waiter.shift f.resume end ensure @halting = false end |