Class: LittleGhost::CodeMode::Javascript::Host::Program
- Inherits:
-
Object
- Object
- LittleGhost::CodeMode::Javascript::Host::Program
- Defined in:
- lib/little_ghost/code_mode/javascript/host.rb
Instance Method Summary collapse
- #deliver(message) ⇒ Object
-
#initialize(id:, source:, tools:, writer:, finished:) ⇒ Program
constructor
A new instance of Program.
- #join(timeout = nil) ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(id:, source:, tools:, writer:, finished:) ⇒ Program
Returns a new instance of Program.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 132 def initialize(id:, source:, tools:, writer:, finished:) @id = id @source = source @tools = tools @writer = writer @finished = finished @incoming = Queue.new @context_mutex = Mutex.new @context = nil @control_identifier = "__littleGhost_control_#{SecureRandom.hex(32)}" @terminating = false @thread = Thread.new { run } @thread.report_on_exception = false end |
Instance Method Details
#deliver(message) ⇒ Object
147 148 149 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 147 def deliver() @incoming << end |
#join(timeout = nil) ⇒ Object
162 163 164 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 162 def join(timeout = nil) @thread.join(timeout) end |
#terminate ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 151 def terminate @incoming << {"type" => "terminate"} context = @context_mutex.synchronize do @terminating = true @context end context&.stop rescue MiniRacer::ContextDisposedError nil end |