Sha256: 7cfd4129bd68f62f205b07f6f7272f84860997dab2c9a12b1bfc9625521fe6d1

Contents?: true

Size: 1.66 KB

Versions: 1

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.03)
    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.2)
    expect(a).to eq [1]
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gb_dispatch-0.0.4 spec/dispatch_spec.rb