Class: RubyAwaitNodejs::Runtime
- Inherits:
-
Object
- Object
- RubyAwaitNodejs::Runtime
- Defined in:
- lib/ruby-await-nodejs/runtime.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#nodejs_cmd ⇒ Object
Returns the value of attribute nodejs_cmd.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#port ⇒ Object
Returns the value of attribute port.
-
#semaphore ⇒ Object
Returns the value of attribute semaphore.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #context_class ⇒ Object
- #deprecated? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Runtime
constructor
A new instance of Runtime.
- #name ⇒ Object
-
#provision_socket ⇒ Object
NOTE: this should be thread-safe.
Constructor Details
#initialize(opts = {}) ⇒ Runtime
Returns a new instance of Runtime.
9 10 11 12 13 14 15 16 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 9 def initialize(opts = {}) srand @debug = opts[:debug] @nodejs_cmd = "node" @pid = nil @semaphore = Mutex.new end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
7 8 9 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 7 def debug @debug end |
#nodejs_cmd ⇒ Object
Returns the value of attribute nodejs_cmd.
7 8 9 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 7 def nodejs_cmd @nodejs_cmd end |
#pid ⇒ Object
Returns the value of attribute pid.
7 8 9 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 7 def pid @pid end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 7 def port @port end |
#semaphore ⇒ Object
Returns the value of attribute semaphore.
7 8 9 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 7 def semaphore @semaphore end |
Instance Method Details
#available? ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 22 def available? ENV["PATH"].split(":").detect do |path| %w{ nodejs node }.detect do |node| File.exist?(File.join(path, node)) || File.symlink?(File.join(path, node)) end end end |
#context_class ⇒ Object
37 38 39 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 37 def context_class RubyAwaitNodejs::Context end |
#deprecated? ⇒ Boolean
33 34 35 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 33 def deprecated? false end |
#name ⇒ Object
18 19 20 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 18 def name "RubyAwaitNodejs" end |
#provision_socket ⇒ Object
NOTE: this should be thread-safe
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby-await-nodejs/runtime.rb', line 42 def provision_socket ensure_startup unless @pid wait_socket = nil checks = 0 max_retries = 12 while checks < max_retries begin checks += 1 wait_socket = UNIXSocket.new(@port) break rescue Errno::ENOENT, Errno::ECONNREFUSED, Errno::ENOTDIR wait_socket = nil sleep 0.5 end end if checks >= max_retries ensure_shutdown raise RuntimeError, "unable to connect to ruby-await-nodejs.js server" end wait_socket end |