Sha256: b3411d7a4fe1cf60ed5db74c0ed7ed6857fcd72d543fc16220f99116c2bdef12

Contents?: true

Size: 698 Bytes

Versions: 2

Compression:

Stored size: 698 Bytes

Contents

# frozen_string_literal: true

require "dry/effects/effect"

module Dry
  module Effects
    module Effects
      class Interrupt < ::Module
        class InterruptEffect < Effect
          option :scope
        end

        def initialize(scope = :default)
          super()

          interrupt = InterruptEffect.new(type: :interrupt, scope: scope)

          module_eval do
            define_method(scope) do |payload = Undefined|
              if Undefined.equal?(payload)
                ::Dry::Effects.yield(interrupt)
              else
                ::Dry::Effects.yield(interrupt.payload(payload))
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-effects-0.3.0 lib/dry/effects/effects/interrupt.rb
dry-effects-0.2.0 lib/dry/effects/effects/interrupt.rb