Sha256: 9686a919e3ec947783055c3a95cd7d927a6a412f8ce62eb4a1938c16ce89c2eb

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'
require 'gb_dispatch'

describe GBDispatch do

  it 'should run dispatch_async' do
    a = []
    GBDispatch.dispatch_async :test do
      sleep(0.01)
      a << 1
    end
    GBDispatch.dispatch_async :test do
      a << 2
    end
    expect(a.empty?).to be_truthy
    sleep(0.02)
    expect(a).to eq [1, 2]
  end

  it 'should run dispatch_async_on_queue' do
    a = []
    GBDispatch.dispatch_async_on_queue :test do
      sleep(0.01)
      a << 1
    end
    GBDispatch.dispatch_async_on_queue :test do
      a << 2
    end
    expect(a.empty?).to be_truthy
    sleep(0.02)
    expect(a).to eq [1, 2]
  end

  it 'should run dispatch_sync' do
    a = []
    GBDispatch.dispatch_async :test do
      sleep(0.02)
      a << 1
    end
    result = GBDispatch.dispatch_sync :test do
      a << 2
      a
    end
    expect(result).to eq [1,2]
  end

  it 'should run dispatch_sync_on_queue' do
    a = []
    GBDispatch.dispatch_async :test do
      sleep(0.02)
      a << 1
    end
    result = GBDispatch.dispatch_sync_on_queue :test do
      a << 2
      a
    end
    expect(result).to eq [1,2]
  end

  it 'should run dispatch_after' do
    a = []
    GBDispatch.dispatch_after 0.1, :test do
      a << 1
    end
    expect(a.empty?).to be_truthy
    sleep(0.15)
    expect(a).to eq [1]
  end

  it 'should run dispatch_after_on_queue' do
    a = []
    GBDispatch.dispatch_after_on_queue 0.1, :test do
      a << 1
    end
    expect(a.empty?).to be_truthy
    sleep(0.15)
    expect(a).to eq [1]
  end

  it 'should return proper queue' do
    queue = GBDispatch.get_queue :test
    expect(queue.name).to eq :test
    expect(queue).to be_a GBDispatch::Queue
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gb_dispatch-0.0.3 spec/dispatch_spec.rb
gb_dispatch-0.0.2 spec/dispatch_spec.rb