Sha256: 71b9991c75d18c8d8e17a3b7c20781b108dfcacd31d27c684db537268185f484

Contents?: true

Size: 756 Bytes

Versions: 4

Compression:

Stored size: 756 Bytes

Contents

module Elevate
  def async(target, &block)
    with_operation(target, 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(target, dsl_block, &block)
    operation = ElevateOperation.alloc.initWithTarget(target)

    if dsl_block
      dsl = DSL.new(&dsl_block)

      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

    yield operation

    operation
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
elevate-0.3.3 lib/elevate/api.rb
elevate-0.3.2 lib/elevate/api.rb
elevate-0.3.1 lib/elevate/api.rb
elevate-0.3 lib/elevate/api.rb