Sha256: afaf2fc21ce8646754f23806781eb79fe025fd7455ace8fa2df35a497077fbde

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

module Elevate
  def async(args = {}, &block)
    with_operation(args, block) do |operation|
      queue.addOperation(operation)
    end
  end

  private

  def queue
    Dispatch.once do
      $elevate_queue = NSOperationQueue.alloc.init
      $elevate_queue.maxConcurrentOperationCount = 1
    end

    $elevate_queue
  end

  def with_operation(args, dsl_block, &block)
    dsl = DSL.new(&dsl_block)

    raise "No task block specified!" unless dsl.task_callback

    operation = ElevateOperation.alloc.initWithTarget(dsl.task_callback, args: args)
    operation.on_start  = Callback.new(self, dsl.start_callback)  if dsl.start_callback
    operation.on_finish = Callback.new(self, dsl.finish_callback) if dsl.finish_callback
    operation.on_update = Callback.new(self, dsl.update_callback)   if dsl.update_callback

    yield operation

    operation
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elevate-0.5.0 lib/elevate/api.rb