Class: Pwrake::NBIO::Writer
- Inherits:
-
Object
- Object
- Pwrake::NBIO::Writer
- Defined in:
- lib/pwrake/nbio.rb
Overview
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
-
#call ⇒ Object
call from Selector.
- #error(e) ⇒ Object
- #flush ⇒ Object
- #halt ⇒ Object
-
#initialize(selector, io) ⇒ Writer
constructor
A new instance of Writer.
-
#put_line(line, ch = nil) ⇒ Object
call from Fiber context.
- #puts(s) ⇒ Object
- #select_io ⇒ Object
-
#write(buf, buffered = false) ⇒ Object
(also: #print)
from Bartender.
Constructor Details
#initialize(selector, io) ⇒ Writer
Returns a new instance of Writer.
150 151 152 153 154 155 |
# File 'lib/pwrake/nbio.rb', line 150 def initialize(selector, io) @selector = selector @io = io @waiter = [] @pool = [] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
157 158 159 |
# File 'lib/pwrake/nbio.rb', line 157 def host @host end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
156 157 158 |
# File 'lib/pwrake/nbio.rb', line 156 def io @io end |
Instance Method Details
#call ⇒ Object
call from Selector
160 161 162 163 164 165 166 |
# File 'lib/pwrake/nbio.rb', line 160 def call w = @waiter @waiter = [] w.each{|f| f.resume} ensure @selector.delete_writer(self) if @waiter.empty? end |
#error(e) ⇒ Object
182 183 184 185 |
# File 'lib/pwrake/nbio.rb', line 182 def error(e) @closed = true raise e end |
#flush ⇒ Object
200 201 202 203 204 205 |
# File 'lib/pwrake/nbio.rb', line 200 def flush until @pool.empty? len = _write(@pool[0]) pop(len) end end |
#halt ⇒ Object
175 176 177 178 179 180 |
# File 'lib/pwrake/nbio.rb', line 175 def halt @halting = true call ensure @halting = false end |
#put_line(line, ch = nil) ⇒ Object
call from Fiber context
169 170 171 172 173 |
# File 'lib/pwrake/nbio.rb', line 169 def put_line(line, ch=nil) line = line.chomp line = "#{ch}:#{line}" if ch write(line+"\n") end |
#puts(s) ⇒ Object
196 197 198 |
# File 'lib/pwrake/nbio.rb', line 196 def puts(s) write(s+"\n") end |
#select_io ⇒ Object
207 208 209 210 211 |
# File 'lib/pwrake/nbio.rb', line 207 def select_io @selector.add_writer(self) if @waiter.empty? @waiter.push(Fiber.current) Fiber.yield end |
#write(buf, buffered = false) ⇒ Object Also known as: print
from Bartender
189 190 191 192 |
# File 'lib/pwrake/nbio.rb', line 189 def write(buf, buffered=false) push(buf) flush unless buffered end |