Sha256: 61c52626d0b0937fb5e91aeb92869e13902d7f1a43a122ed47e3703524fbc30a
Contents?: true
Size: 1020 Bytes
Versions: 1
Compression:
Stored size: 1020 Bytes
Contents
module QueueToTheFuture # A proxy object for the future return value of a block. class Job (instance_methods - %w[__send__ __id__ object_id inspect]).each { |meth| undef_method(meth) } # Creates a job and schedules it by calling {Coordinator#schedule}. # # @param [List] *args The list of arguments to pass to the given block # @param [Proc] &block The block to be executed def initialize(*args, &block) @args = args @block = block Coordinator::instance.schedule(self) end # Execute the job. # # This is called by the worker the job gets assigned to. # @return [nil] def __execute__ @result = @block.call(*@args); nil end # Allows the job to behave as the return value of the block. # # Accessing any method on the job will cause code to block # until the job is completed. def method_missing(*args, &block) Thread.pass while !defined?(@result) @result.send(*args, &block) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
queue_to_the_future-0.1.1 | lib/queue_to_the_future/job.rb |