Class: Solargraph::LanguageServer::Host::MessageWorker
- Inherits:
-
Object
- Object
- Solargraph::LanguageServer::Host::MessageWorker
- Defined in:
- lib/solargraph/language_server/host/message_worker.rb
Overview
A serial worker Thread to handle message.
this make check pending message possible, and maybe cancelled to speedup process
Instance Method Summary collapse
-
#initialize(host) ⇒ MessageWorker
constructor
A new instance of MessageWorker.
-
#messages ⇒ Object
pending handle messages.
- #queue(message) ⇒ void
- #start ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #tick ⇒ Object
Constructor Details
#initialize(host) ⇒ MessageWorker
Returns a new instance of MessageWorker.
11 12 13 14 15 16 |
# File 'lib/solargraph/language_server/host/message_worker.rb', line 11 def initialize(host) @host = host @mutex = Mutex.new @resource = ConditionVariable.new @stopped = true end |
Instance Method Details
#messages ⇒ Object
pending handle messages
19 20 21 |
# File 'lib/solargraph/language_server/host/message_worker.rb', line 19 def @messages ||= [] end |
#queue(message) ⇒ void
This method returns an undefined value.
33 34 35 36 37 38 |
# File 'lib/solargraph/language_server/host/message_worker.rb', line 33 def queue() @mutex.synchronize do .push() @resource.signal end end |
#start ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/solargraph/language_server/host/message_worker.rb', line 40 def start return unless @stopped @stopped = false Thread.new do tick until stopped? end end |
#stop ⇒ Object
27 28 29 |
# File 'lib/solargraph/language_server/host/message_worker.rb', line 27 def stop @stopped = true end |
#stopped? ⇒ Boolean
23 24 25 |
# File 'lib/solargraph/language_server/host/message_worker.rb', line 23 def stopped? @stopped end |
#tick ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/solargraph/language_server/host/message_worker.rb', line 48 def tick = @mutex.synchronize do @resource.wait(@mutex) if .empty? .shift end handler = @host.receive() handler && handler.send_response end |