Sha256: f797bfaceda3e07514a6b273e752e92ecc1ac644d3f934ffc3091dc758deb5c4

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'ruby/reflection/support/shift_reset'
require 'continuation' unless defined? callcc

module Ruby
  class Reflection
    class ThreadMirror < ObjectMirror
      include AbstractReflection::ThreadMirror
      include ShiftReset
      reflect! Thread
      Frame = Struct.new :method, :index, :file, :line, :thread

      def status
        s = @subject.status
        if s.respond_to? :to_str
          s.to_str
        elsif s.nil?
          "aborted"
        else
          "dead"
        end
      end

      def run
        @subject.run
      end

      def stack
        if bt = @subject.backtrace
          bt.each_with_index.collect do |str, idx|
            file, line, method_spec = str.split(':')
            method_spec =~ /\`([^']+)'/
            method = $1
            frame = Frame.new method, idx, file, line, self
            reflection.reflect frame
          end
        else
          []
        end
      end

      def return_value
        return nil if @subject.alive?
        @subject.value
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubymirrors-0.0.3 lib/ruby/reflection/thread_mirror.rb
rubymirrors-0.0.2 lib/ruby/reflection/thread_mirror.rb
rubymirrors-0.0.1 lib/ruby/reflection/thread_mirror.rb