Class: Steep::Server::WorkerProcess
- Inherits:
-
Object
- Object
- Steep::Server::WorkerProcess
- Defined in:
- lib/steep/server/worker_process.rb
Instance Attribute Summary collapse
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#wait_thread ⇒ Object
readonly
Returns the value of attribute wait_thread.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Class Method Summary collapse
- .spawn_code_workers(steepfile:, count: [Etc.nprocessors-3, 1].max) ⇒ Object
- .spawn_worker(type, name:, steepfile:) ⇒ Object
Instance Method Summary collapse
- #<<(message) ⇒ Object
-
#initialize(reader:, writer:, stderr:, wait_thread:) ⇒ WorkerProcess
constructor
A new instance of WorkerProcess.
- #read(&block) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(reader:, writer:, stderr:, wait_thread:) ⇒ WorkerProcess
Returns a new instance of WorkerProcess.
10 11 12 13 14 15 |
# File 'lib/steep/server/worker_process.rb', line 10 def initialize(reader:, writer:, stderr:, wait_thread:) @reader = reader @writer = writer @stderr = stderr @wait_thread = wait_thread end |
Instance Attribute Details
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
4 5 6 |
# File 'lib/steep/server/worker_process.rb', line 4 def reader @reader end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
6 7 8 |
# File 'lib/steep/server/worker_process.rb', line 6 def stderr @stderr end |
#wait_thread ⇒ Object (readonly)
Returns the value of attribute wait_thread.
8 9 10 |
# File 'lib/steep/server/worker_process.rb', line 8 def wait_thread @wait_thread end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
5 6 7 |
# File 'lib/steep/server/worker_process.rb', line 5 def writer @writer end |
Class Method Details
.spawn_code_workers(steepfile:, count: [Etc.nprocessors-3, 1].max) ⇒ Object
39 40 41 42 43 |
# File 'lib/steep/server/worker_process.rb', line 39 def self.spawn_code_workers(steepfile:, count: [Etc.nprocessors-3, 1].max) count.times.map do |i| spawn_worker(:code, name: "code@#{i}", steepfile: steepfile) end end |
.spawn_worker(type, name:, steepfile:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/steep/server/worker_process.rb', line 17 def self.spawn_worker(type, name:, steepfile:) log_level = %w(debug info warn error fatal unknown)[Steep.logger.level] command = case type when :code ["steep", "worker", "--code", "--name=#{name}", "--log-level=#{log_level}", "--steepfile=#{steepfile}"] when :signature ["steep", "worker", "--signature", "--name=#{name}", "--log-level=#{log_level}", "--steepfile=#{steepfile}"] when :interaction ["steep", "worker", "--interaction", "--name=#{name}", "--log-level=#{log_level}", "--steepfile=#{steepfile}"] else raise end stdin, stdout, thread = Open3.popen2(*command, pgroup: true) stderr = nil writer = LanguageServer::Protocol::Transport::Io::Writer.new(stdin) reader = LanguageServer::Protocol::Transport::Io::Reader.new(stdout) new(reader: reader, writer: writer, stderr: stderr, wait_thread: thread) end |
Instance Method Details
#<<(message) ⇒ Object
45 46 47 |
# File 'lib/steep/server/worker_process.rb', line 45 def <<() writer.write() end |
#read(&block) ⇒ Object
49 50 51 |
# File 'lib/steep/server/worker_process.rb', line 49 def read(&block) reader.read(&block) end |
#shutdown ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/steep/server/worker_process.rb', line 53 def shutdown self << { method: :shutdown, params: nil } self << { method: :exit, params: nil } writer.io.close() @wait_thread.join() end |