class ForkBreak::Process
Attributes
breakpoint_setter[RW]
return_value[R]
Public Class Methods
new(debug = false, &block)
click to toggle source
# File lib/fork_break/process.rb, line 11 def initialize(debug = false, &block) @debug = debug @fork = Fork.new(:return, :to_fork, :from_fork) do |child_fork| self.class.breakpoint_setter = breakpoints = BreakpointSetter.new(child_fork, debug) breakpoints << :forkbreak_start returned_value = block.call(breakpoints) breakpoints << :forkbreak_end self.class.breakpoint_setter = nil returned_value end end
Public Instance Methods
finish()
click to toggle source
# File lib/fork_break/process.rb, line 53 def finish run_until(:forkbreak_end) end
run_until(breakpoint)
click to toggle source
# File lib/fork_break/process.rb, line 25 def run_until(breakpoint) @next_breakpoint = breakpoint @fork.execute unless @fork.pid puts "Parent is sending object #{breakpoint} to #{@fork.pid}" if @debug @fork.send_object(breakpoint) self end
wait(options = {})
click to toggle source
# File lib/fork_break/process.rb, line 33 def wait(options = {}) # A timeout value of nil will execute the block without any timeout Timeout.timeout(options[:timeout], WaitTimeout) do loop do brk = @fork.receive_object puts "Parent is receiving object #{brk} from #{@fork.pid}" if @debug @return_value = @fork.return_value if brk == :forkbreak_end if brk == @next_breakpoint return self elsif brk == :forkbreak_end raise BreakpointNotReachedError, "Never reached breakpoint #{@next_breakpoint.inspect}" end end end rescue EOFError => exception raise @fork.exception || exception end