class Dunder::Future

Constants

FORBIDDEN

Attributes

_thread[R]

Public Class Methods

ensure_threads_finished(timeout = nil) click to toggle source
# File lib/dunder.rb, line 13
def self.ensure_threads_finished(timeout = nil)
  @@threads.values.each do |t|
    raise 'Thread did not timeout in time' unless t.join(timeout)
  end
end
new(group = nil,&block) click to toggle source
# File lib/dunder.rb, line 21
def initialize(group = nil,&block)
  raise ArgumentError,"No block was passed for execution" unless block
  @_thread = group ? group.start_thread(&block) : Thread.start(&block)
  @@threads[@_thread.object_id] = @_thread
end
threads() click to toggle source
# File lib/dunder.rb, line 9
def self.threads
  @@threads
end

Public Instance Methods

__getobj__() click to toggle source
Calls superclass method
# File lib/dunder.rb, line 27
def __getobj__
  # Optimizing a bit
  return super if @delegate_sd_obj
  __setobj__(@_thread.value)
  #@delegate_sd_obj = @_thread.value
  if FORBIDDEN.include?(super.class)
    error = "Your block returned a #{super.class} and because of how ruby handles #{FORBIDDEN.join(", ")}"
    error << " the #{super.class} won't behave correctly. There are two known workarounds:"
    error << " add the suffix ._thread.value or construct the block to return a array of length 1 and say lazy_array.first."
    error << "Ex: puts lazy_object becomes lazy_object._thread.value"
    raise ArgumentError,error
  end
  @@threads.delete @_thread.object_id
  super
end
class() click to toggle source
# File lib/dunder.rb, line 43
def class
  __getobj__.class
end