Sha256: 7b60faa2b242cbab25a9aa881e8b91ea81943fd557c1e6d6cbef4114a1ca6c94

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

RSpec.describe Celluloid::Future, actor_system: :global do
  it "creates future objects that can be retrieved later" do
    future = Celluloid::Future.new { 40 + 2 }
    expect(future.value).to eq(42)
  end

  it "passes arguments to future blocks" do
    future = Celluloid::Future.new(40) { |n| n + 2 }
    expect(future.value).to eq(42)
  end

  it "reraises exceptions that occur when the value is retrieved" do
    class ExampleError < StandardError; end

    future = Celluloid::Future.new { fail ExampleError, "oh noes crash!" }
    expect { future.value }.to raise_exception(ExampleError)
  end

  it "knows if it's got a value yet" do
    queue = Queue.new
    future = Celluloid::Future.new { queue.pop }

    expect(future).not_to be_ready
    queue << nil # let it continue

    Specs.sleep_and_wait_until { future.ready? }

    expect(future).to be_ready
  end

  it "raises TimeoutError when the future times out" do
    future = Celluloid::Future.new { sleep 2 }
    expect { future.value(1) }.to raise_exception(Celluloid::TimeoutError)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
celluloid-0.17.0 spec/celluloid/future_spec.rb