lib/byebug/dap/server.rb in byebug-dap-0.1.1 vs lib/byebug/dap/server.rb in byebug-dap-0.1.2
- old
+ new
@@ -18,17 +18,15 @@
def_delegators :@in, :close_read, :bytes, :chars, :codepoints, :each, :each_byte, :each_char, :each_codepoint, :each_line, :getbyte, :getc, :gets, :lines, :pread, :print, :printf, :read, :read_nonblock, :readbyte, :readchar, :readline, :readlines, :readpartial, :sysread, :ungetbyte, :ungetc
def_delegators :@out, :<<, :close_write, :putc, :puts, :pwrite, :syswrite, :write, :write_nonblock
public :<<, :bytes, :chars, :close_read, :close_write, :codepoints, :each, :each_byte, :each_char, :each_codepoint, :each_line, :getbyte, :getc, :gets, :lines, :pread, :print, :printf, :putc, :puts, :pwrite, :read, :read_nonblock, :readbyte, :readchar, :readline, :readlines, :readpartial, :sysread, :syswrite, :ungetbyte, :ungetc, :write, :write_nonblock
end
- def initialize(&block)
+ def initialize
@started = false
- if block_given?
- @on_start = block
- @mu = Mutex.new
- @cond = ConditionVariable.new
- end
+ @mu = Mutex.new
+ @cond = ConditionVariable.new
+ @configured = false
end
def start(host, port = 0)
case host
when :stdio
@@ -59,10 +57,20 @@
@started = true
launch STDIO.new
end
+ def wait_for_client
+ @mu.synchronize do
+ loop do
+ return if @configured
+
+ @cond.wait(@mu)
+ end
+ end
+ end
+
private
def launch(server)
DebugThread.new do
if server.respond_to?(:accept)
@@ -72,22 +80,22 @@
else
debug server
end
end
- return unless defined?(@on_start)
-
- @mu.synchronize { @cond.wait(@mu) }
-
- @on_start.call
+ self
end
def debug(session)
Context.interface = Byebug::DAP::Interface.new(session)
Context.processor = Byebug::DAP::CommandProcessor
- signal_start = ->(_) { @mu.synchronize { @cond.signal } } if defined?(@on_start)
- Byebug::DAP::Controller.new(Context.interface, signal_start).run
+ Byebug::DAP::Controller.new(Context.interface) do
+ @mu.synchronize do
+ @configured = true
+ @cond.broadcast
+ end
+ end.run
end
end
end
end