Class: WavesLib::RootWrapper

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/waves_lib/root_wrapper.rb

Overview

Main class for creating connection

Instance Method Summary collapse

Constructor Details

#initialize(node_bin_path = "node") ⇒ RootWrapper



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/waves_lib/root_wrapper.rb', line 14

def initialize(node_bin_path = "node")
  entrypoint = File.join(__dir__ || "", "..", "..", "js", "worker.js")

  @port = T.let(find_empty_port, Integer)

  cmd = "#{node_bin_path} #{entrypoint}"
  env = { "PORT" => @port.to_s }

  @pid = T.let(Process.spawn(env, cmd), Integer)

  wait_for_server_ready
  create_wrappers
end

Instance Method Details

#destroyObject



30
31
32
33
# File 'lib/waves_lib/root_wrapper.rb', line 30

def destroy
  @socket&.close
  Process.kill("HUP", @pid)
end