Sha256: 80123cd52e0b0905842b79346810a28ddfe5b8893e7de144f916e665775f9564
Contents?: true
Size: 752 Bytes
Versions: 14
Compression:
Stored size: 752 Bytes
Contents
require "thread" module Stud class Task def initialize(*args, &block) # A queue to receive the result of the block # TODO(sissel): Don't use a queue, just store it in an instance variable. @queue = Queue.new @thread = Thread.new(@queue, *args) do |queue, *args| begin result = block.call(*args) queue << [:return, result] rescue => e queue << [:exception, e] end end # thread end # def initialize def wait @thread.join reason, result = @queue.pop if reason == :exception #raise StandardError.new(result) raise result else return result end end # def wait end # class Task end # module Stud
Version data entries
14 entries across 14 versions & 1 rubygems