Class: Neovim::Session Private
- Inherits:
-
Object
- Object
- Neovim::Session
- Includes:
- Logging
- Defined in:
- lib/neovim/session.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.
Wraps an event loop in a synchronous API using Fibers.
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
- #request_id ⇒ Object writeonly private
Instance Method Summary collapse
-
#initialize(event_loop) ⇒ Session
constructor
private
A new instance of Session.
- #notify(method, *args) ⇒ Object private
-
#request(method, *args) ⇒ Object
private
Make an RPC request and return its response.
- #respond(request_id, value, error = nil) ⇒ Object private
- #run(&block) ⇒ Object private
- #shutdown ⇒ Object private
- #stop ⇒ Object private
Methods included from Logging
Constructor Details
#initialize(event_loop) ⇒ Session
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 Session.
13 14 15 16 17 18 19 20 |
# File 'lib/neovim/session.rb', line 13 def initialize(event_loop) @event_loop = event_loop @main_thread = Thread.current @main_fiber = Fiber.current @response_handlers = Hash.new(-> {}) = [] @request_id = 0 end |
Instance Attribute Details
#request_id=(value) ⇒ Object (writeonly)
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.
11 12 13 |
# File 'lib/neovim/session.rb', line 11 def request_id=(value) @request_id = value end |
Instance Method Details
#notify(method, *args) ⇒ 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.
70 71 72 |
# File 'lib/neovim/session.rb', line 70 def notify(method, *args) @event_loop.notify(method, *args) end |
#request(method, *args) ⇒ 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.
Make an RPC request and return its response.
If this method is called inside a callback, we are already inside a Fiber handler. In that case, we write to the stream and yield the Fiber. Once the response is received, resume the Fiber and return the result.
If this method is called outside a callback, write to the stream and run the event loop until a response is received. Messages received in the meantime are enqueued to be handled later.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/neovim/session.rb', line 46 def request(method, *args) main_thread_only do @request_id += 1 blocking = Fiber.current == @main_fiber log(:debug) do { method_name: method, request_id: @request_id, blocking: blocking, arguments: args } end @event_loop.request(@request_id, method, *args) response = blocking ? blocking_response : yielding_response response.error ? raise(response.error) : response.value end end |
#respond(request_id, value, error = nil) ⇒ 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.
66 67 68 |
# File 'lib/neovim/session.rb', line 66 def respond(request_id, value, error=nil) @event_loop.respond(request_id, value, error) end |
#run(&block) ⇒ 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.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/neovim/session.rb', line 22 def run(&block) @running = true while = .shift Fiber.new { .received(@response_handlers, &block) }.resume end return unless @running @event_loop.run do || Fiber.new { .received(@response_handlers, &block) }.resume end 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.
74 75 76 77 |
# File 'lib/neovim/session.rb', line 74 def shutdown @running = false @event_loop.shutdown 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.
79 80 81 82 |
# File 'lib/neovim/session.rb', line 79 def stop @running = false @event_loop.stop end |