lib/elevate/task_context.rb in elevate-0.6.0 vs lib/elevate/task_context.rb in elevate-0.7.0
- old
+ new
@@ -1,18 +1,27 @@
module Elevate
# A blank slate for hosting task blocks.
#
# Because task blocks run in another thread, it is dangerous to expose them
- # to the calling context. This class acts as a sandbox for task blocks.
+ # to the calling context. This class acts as a sandbox for task blocks.
#
# @api private
class TaskContext
- def initialize(args, &block)
- metaclass = class << self; self; end
- metaclass.send(:define_method, :execute, &block)
+ def initialize(block, channel, args)
+ @__block = block
+ @__channel = channel
+ @__args = args
+ end
- args.each do |key, value|
- instance_variable_set("@#{key}", value)
- end
+ def execute
+ instance_exec(&@__block)
+ end
+
+ def task_args
+ @__args
+ end
+
+ def update(*args)
+ @__channel << args if @__channel
end
end
end