Class: Neovim::Session::EventLoop Private
- Inherits:
-
Object
- Object
- Neovim::Session::EventLoop
- Includes:
- Logging
- Defined in:
- lib/neovim/session/event_loop.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The lowest level interface to reading from and writing to nvim.
Class Method Summary collapse
-
.child(_argv) ⇒ Object
private
Spawn and connect to a child
nvimprocess. -
.stdio ⇒ Object
private
Connect to the current process’s standard streams.
-
.tcp(host, port) ⇒ Object
private
Connect to a TCP socket.
-
.unix(path) ⇒ Object
private
Connect to a UNIX domain socket.
Instance Method Summary collapse
-
#initialize(rd, wr = rd) ⇒ EventLoop
constructor
private
A new instance of EventLoop.
-
#run ⇒ Object
private
Run the event loop, reading from the underlying
IOand yielding received messages to the block. -
#shutdown ⇒ Object
private
Stop the event loop and close underlying IOs.
-
#stop ⇒ Object
private
Stop the event loop.
-
#write(data) ⇒ Object
private
Write data to the underlying
IO.
Methods included from Logging
Constructor Details
#initialize(rd, wr = rd) ⇒ EventLoop
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of EventLoop.
41 42 43 44 |
# File 'lib/neovim/session/event_loop.rb', line 41 def initialize(rd, wr=rd) @rd, @wr = rd, wr @running = false end |
Class Method Details
.child(_argv) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Spawn and connect to a child nvim process.
25 26 27 28 29 30 31 32 33 |
# File 'lib/neovim/session/event_loop.rb', line 25 def self.child(_argv) argv = _argv.include?("--embed") ? _argv : _argv + ["--embed"] io = IO.popen(argv, "rb+").tap do |_io| Process.detach(_io.pid) end new(io) end |
.stdio ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Connect to the current process’s standard streams. This is used to promote the current process to a Ruby plugin host.
37 38 39 |
# File 'lib/neovim/session/event_loop.rb', line 37 def self.stdio new(STDIN, STDOUT) end |
.tcp(host, port) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Connect to a TCP socket.
13 14 15 16 |
# File 'lib/neovim/session/event_loop.rb', line 13 def self.tcp(host, port) socket = Socket.tcp(host, port) new(socket) end |
.unix(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Connect to a UNIX domain socket.
19 20 21 22 |
# File 'lib/neovim/session/event_loop.rb', line 19 def self.unix(path) socket = Socket.unix(path) new(socket) end |
Instance Method Details
#run ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run the event loop, reading from the underlying IO and yielding received messages to the block.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/neovim/session/event_loop.rb', line 66 def run @running = true loop do break unless @running = @rd.readpartial(1024 * 16) debug("received #{.inspect}") yield if block_given? end rescue EOFError info("got EOFError") rescue => e fatal("got unexpected error #{e.inspect}") debug(e.backtrace.join("\n")) end |
#shutdown ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Stop the event loop and close underlying IOs.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/neovim/session/event_loop.rb', line 88 def shutdown stop [@rd, @wr].each do |io| begin io.close rescue IOError end end end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Stop the event loop.
83 84 85 |
# File 'lib/neovim/session/event_loop.rb', line 83 def stop @running = false end |
#write(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Write data to the underlying IO. This will block until all the data has been written.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/neovim/session/event_loop.rb', line 48 def write(data) start = 0 size = data.size debug("writing #{data.inspect}") begin while start < size start += @wr.write_nonblock(data[start..-1]) end self rescue IO::WaitWritable IO.select(nil, [@wr], nil, 1) retry end end |