Class: Termfront::AsyncWriter
- Inherits:
-
Object
- Object
- Termfront::AsyncWriter
- Defined in:
- lib/termfront/async_writer.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io) ⇒ AsyncWriter
constructor
A new instance of AsyncWriter.
- #raw(&block) ⇒ Object
- #syswrite(data) ⇒ Object
- #winsize ⇒ Object
Constructor Details
#initialize(io) ⇒ AsyncWriter
Returns a new instance of AsyncWriter.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/termfront/async_writer.rb', line 5 def initialize(io) @io = io @queue = Queue.new @closed = false @thread = Thread.new do Thread.current.report_on_exception = false while (data = @queue.pop) begin TerminalOutput.write_all(@io, data) rescue IOError, Errno::EBADF, Errno::EPIPE break end end end end |
Instance Method Details
#close ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/termfront/async_writer.rb', line 37 def close return if @closed @closed = true @queue.push(nil) @thread.join end |
#raw(&block) ⇒ Object
33 34 35 |
# File 'lib/termfront/async_writer.rb', line 33 def raw(&block) @io.raw(&block) end |
#syswrite(data) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/termfront/async_writer.rb', line 21 def syswrite(data) raise IOError, "writer closed" if @closed @queue.clear if @queue.size >= 1 @queue.push(data) data.bytesize end |
#winsize ⇒ Object
29 30 31 |
# File 'lib/termfront/async_writer.rb', line 29 def winsize @io.winsize end |