Sha256: b446a4d1265f5dd218674fd0398aa394e335707a8b0c8d173d47b124de68bce7

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

class CodeEvaluation
  class << self
    def wait_for_eval_thread(&block)
      eval_thread = Thread.start do
        value_proc = Proc.new do
          if Maglev::System.__DBEPersistenceMode
            Maglev.persistent do
              block.call
            end
          else
            Maglev.transient do
              block.call
            end
          end
        end

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

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

          Thread.current[:result] = eval_result
          Thread.current[:manual_stop] = true

          if is_exception
            Thread.stop
            Thread.current[:manual_stop] = false
            eval_result[1].__exception.__resume
          end
        end

        Thread.current[:manual_stop] = true
      end

      sleep 0.1 until eval_thread.stop? and eval_thread[:manual_stop]

      result = eval_thread[:result]
      return result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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