lib/elevate/api.rb in elevate-0.3.3 vs lib/elevate/api.rb in elevate-0.4.0

- old
+ new

@@ -1,8 +1,8 @@ module Elevate - def async(target, &block) - with_operation(target, block) do |operation| + def async(args = {}, &block) + with_operation(args, block) do |operation| queue.addOperation(operation) end end private @@ -14,18 +14,17 @@ end $elevate_queue end - def with_operation(target, dsl_block, &block) - operation = ElevateOperation.alloc.initWithTarget(target) + def with_operation(args, dsl_block, &block) + dsl = DSL.new(&dsl_block) - if dsl_block - dsl = DSL.new(&dsl_block) + raise "No task block specified!" unless dsl.task_callback - operation.on_started = Callback.new(self, operation, dsl.started_callback) if dsl.started_callback - operation.on_finished = Callback.new(self, operation, dsl.finished_callback) if dsl.finished_callback - end + operation = ElevateOperation.alloc.initWithTarget(dsl.task_callback, args: args) + operation.on_started = Callback.new(self, dsl.started_callback) if dsl.started_callback + operation.on_finished = Callback.new(self, dsl.finished_callback) if dsl.finished_callback yield operation operation end