Class: Neovim::MsgpackStream
- Inherits:
-
Object
- Object
- Neovim::MsgpackStream
- Includes:
- Logging
- Defined in:
- lib/neovim/msgpack_stream.rb
Overview
Handles serializing RPC messages to MessagePack and passing them to the event loop
Instance Method Summary collapse
-
#initialize(event_loop) ⇒ MsgpackStream
constructor
A new instance of MsgpackStream.
-
#run(session = nil) ⇒ void
Run the event loop, yielding deserialized messages to the block.
-
#shutdown ⇒ void
Shut down the event loop.
-
#stop ⇒ void
Stop the event loop.
-
#write(msg) ⇒ self
Serialize an RPC message to and write it to the event loop.
Constructor Details
#initialize(event_loop) ⇒ MsgpackStream
Returns a new instance of MsgpackStream.
10 11 12 13 |
# File 'lib/neovim/msgpack_stream.rb', line 10 def initialize(event_loop) @event_loop = event_loop @unpacker = MessagePack::Unpacker.new end |
Instance Method Details
#run(session = nil) ⇒ void
This method returns an undefined value.
Run the event loop, yielding deserialized messages to the block.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/neovim/msgpack_stream.rb', line 33 def run(session=nil) register_types(session) @event_loop.run do |data| @unpacker.feed_each(data) do |msg| debug("received #{msg.inspect}") yield msg if block_given? end end rescue => e fatal("got unexpected error #{e}") debug(e.backtrace.join("\n")) end |
#shutdown ⇒ void
This method returns an undefined value.
Shut down the event loop.
59 60 61 |
# File 'lib/neovim/msgpack_stream.rb', line 59 def shutdown @event_loop.shutdown end |
#stop ⇒ void
This method returns an undefined value.
Stop the event loop.
51 52 53 |
# File 'lib/neovim/msgpack_stream.rb', line 51 def stop @event_loop.stop end |
#write(msg) ⇒ self
Serialize an RPC message to and write it to the event loop.
21 22 23 24 25 |
# File 'lib/neovim/msgpack_stream.rb', line 21 def write(msg) debug("writing #{msg.inspect}") @event_loop.write(MessagePack.pack(msg)) self end |