Class: Speednode::Runtime

Inherits:
ExecJS::Runtime show all
Defined in:
lib/speednode/runtime.rb,
lib/speednode/runtime/vm.rb,
lib/speednode/runtime/context.rb,
lib/speednode/runtime/vm_command.rb

Defined Under Namespace

Classes: Context, VM, VMCommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ExecJS::Runtime

#permissive_bench, #permissive_compile, #permissive_eval, #permissive_exec

Constructor Details

#initialize(options) ⇒ Runtime

Returns a new instance of Runtime.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/speednode/runtime.rb', line 17

def initialize(options)
  @name        = options[:name]
  @binary      = ::Speednode::NodeCommand.cached(options[:command])
  @runner_path = options[:runner_path]
  @vm = VM.new(binary: @binary, source_maps: '--enable-source-maps', runner_path: @runner_path)
  @encoding    = options[:encoding]
  @deprecated  = !!options[:deprecated]
  @popen_options = {}
  @popen_options[:external_encoding] = @encoding if @encoding
  @popen_options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
  @contexts = {} 
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/speednode/runtime.rb', line 15

def name
  @name
end

#vmObject (readonly)

Returns the value of attribute vm.



15
16
17
# File 'lib/speednode/runtime.rb', line 15

def vm
  @vm
end

Class Method Details

.attach_proc(context_id, func, run_block) ⇒ Object



3
4
5
# File 'lib/speednode/runtime.rb', line 3

def self.attach_proc(context_id, func, run_block)
  attached_procs[context_id] = { func => run_block }
end

.attached_procsObject



7
8
9
# File 'lib/speednode/runtime.rb', line 7

def self.attached_procs
  @attached_procs ||= {}
end

.respondersObject



11
12
13
# File 'lib/speednode/runtime.rb', line 11

def self.responders
  @responders ||= {}
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/speednode/runtime.rb', line 47

def available?
  @binary ? true : false
end

#deprecated?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/speednode/runtime.rb', line 51

def deprecated?
  @deprecated
end

#register_context(uuid, context) ⇒ Object



30
31
32
# File 'lib/speednode/runtime.rb', line 30

def register_context(uuid, context)
  @contexts[uuid] = context
end

#stop_context(context) ⇒ Object



43
44
45
# File 'lib/speednode/runtime.rb', line 43

def stop_context(context)
  unregister_context(context.instance_variable_get(:@uuid))
end

#unregister_context(uuid) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/speednode/runtime.rb', line 34

def unregister_context(uuid)
  context = @contexts.delete(uuid)
  if context && @vm
    ObjectSpace.undefine_finalizer(context)
    @vm.delete_context(uuid) rescue nil # if delete_context fails, the vm exited before probably
  end
  @vm.stop if @contexts.size == 0 && @vm.started?
end