Sha256: 6cd1878ed048af4a10e22478c3af2e3ebf7194eeb5088e197c10d908ac40dab5

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Mdbe
  class << self
    def install_rails_debugger
      require "mdbe/action_controller_debug_patch"
    end

    def halt(inner_exception = nil)
      halt_proc = Proc.new do
        nil.pause
      end

      halt_proc.__call_and_rescue do |eval_result|
        is_exception = eval_result[0]

        if is_exception
          if inner_exception == nil
            Thread.current.__set_exception(eval_result[1])
          else
            Thread.current.__set_exception(inner_exception)
          end

          Thread.current[:is_rails_thread] = true
          eval_result[1] = Thread.current

          halted_threads.push(Thread.current)
          Thread.current[:manual_stop] = true
          Thread.stop
          Thread.current[:manual_stop] = false
          halted_threads.delete(Thread.current)
          eval_result[1].__exception.__resume
        else
          puts "ERROR: expected a Halt. __call_and_rescue not working correctly."
          Thread.current.__set_exception(nil)
        end
      end
    end

    def halted_threads
      @halted_threads ||= []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mdbe-0.1.0 lib/mdbe/halt.rb