Sha256: 147223d4f8206bbeff9302cc143625be1a16f8f892d367d98cdcf9dadebd46a3

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require "spec_helper"
require "plumbing/actor/async"
require "plumbing/actor/threaded"

RSpec.describe "await" do
  # standard:disable Lint/ConstantDefinitionInBlock
  class Person
    include Plumbing::Actor
    async :name
    def initialize name
      @name = name
    end
    attr_reader :name
  end
  # standard:enable Lint/ConstantDefinitionInBlock

  [:inline, :async, :threaded].each do |mode|
    context "#{mode} mode" do
      around :example do |example|
        Sync do
          Plumbing.configure mode: mode, &example
        end
      end

      it "awaits a result from the actor directly" do
        @person = Person.start "Alice"

        expect(@person.name.value).to eq "Alice"
      end

      it "uses a block to await the result from the actor" do
        @person = Person.start "Alice"

        expect(await { @person.name }).to eq "Alice"
      end

      it "uses a block to immediately access non-actor objects" do
        @person = "Bob"
        expect(await { @person }).to eq "Bob"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
standard-procedure-plumbing-0.4.3 spec/examples/await_spec.rb
standard-procedure-plumbing-0.4.2 spec/examples/await_spec.rb
standard-procedure-plumbing-0.4.1 spec/examples/await_spec.rb