Sha256: 63be335deed540d9e40a7fa1ca1822ebc9e8e1074d8b922fe1f520504e89978e

Contents?: true

Size: 794 Bytes

Versions: 2

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

RSpec.describe FiniteMachine, 'async callbacks' do
  it "permits async callback" do
    called = []
    fsm = FiniteMachine.new do
      initial :green, silent: false

      event :slow,  :green  => :yellow
      event :go,    :yellow => :green

      on_enter  :green,  :async  do |event| called << 'on_enter_green' end
      on_before :slow,   :async  do |event| called << 'on_before_slow'  end
      on_exit   :yellow, :async  do |event| called << 'on_exit_yellow' end
      on_after  :go,     :async  do |event| called << 'on_after_go'     end
    end
    fsm.slow
    fsm.go
    sleep 0.1
    expect(called).to match_array([
      'on_enter_green',
      'on_before_slow',
      'on_exit_yellow',
      'on_enter_green',
      'on_after_go'
    ])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finite_machine-0.12.1 spec/unit/async_callbacks_spec.rb
finite_machine-0.12.0 spec/unit/async_callbacks_spec.rb