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:, messages: nil) ⇒ Program
constructor
A new instance of Program.
- #join(timeout = nil) ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(id:, source:, tools:, writer:, finished:, messages: nil) ⇒ Program
Returns a new instance of Program.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 145 def initialize(id:, source:, tools:, writer:, finished:, messages: nil) @id = id @source = source @tools = tools @messages = DEFAULT_MESSAGES.merge( || {}).freeze @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
161 162 163 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 161 def deliver() @incoming << end |
#join(timeout = nil) ⇒ Object
176 177 178 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 176 def join(timeout = nil) @thread.join(timeout) end |
#terminate ⇒ Object
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/little_ghost/code_mode/javascript/host.rb', line 165 def terminate @incoming << {"type" => "terminate"} context = @context_mutex.synchronize do @terminating = true @context end context&.stop rescue MiniRacer::ContextDisposedError nil end |