Sha256: 1e9a9c9797c79a78948e9ed1ea120e27f4ede99c8a8de0cf017592bb005e7c18

Contents?: true

Size: 829 Bytes

Versions: 3

Compression:

Stored size: 829 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Effects
    module Providers
      class Interrupt < Provider[:interrupt]
        param :scope, default: -> { :default }

        def interrupt(*payload)
          Instructions.Raise(halt.new(payload))
        end

        # Yield the block with the handler installed
        #
        # @api private
        def call
          [false, yield]
        rescue halt => e
          [true, e.payload[0]]
        end

        def halt
          Halt[scope]
        end

        # @return [String]
        # @api public
        def represent
          "interrupt[#{scope}]"
        end

        # @param [Effect] effect
        # @return [Boolean]
        # @api public
        def provide?(effect)
          super && scope.equal?(effect.scope)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-effects-0.4.1 lib/dry/effects/providers/interrupt.rb
dry-effects-0.4.0 lib/dry/effects/providers/interrupt.rb
dry-effects-0.3.1 lib/dry/effects/providers/interrupt.rb