Sha256: a9e8671b151f5aebf41704e18e53d168555180ce42fbceea2acf320eb90f8a3d

Contents?: true

Size: 846 Bytes

Versions: 2

Compression:

Stored size: 846 Bytes

Contents

# frozen_string_literal: true

require 'dry/core/constants'
require 'dry/effects/version'
require 'dry/effects/container'
require 'dry/effects/errors'
require 'dry/effects/instructions/raise'

module Dry
  module Effects
    include Core::Constants

    class Error < StandardError; end

    @effects = Container.new
    @providers = Container.new

    class << self
      attr_reader :effects, :providers

      def yield(effect)
        result = ::Fiber.yield(effect)

        if result.is_a?(Instruction)
          result.()
        else
          result
        end
      rescue FiberError => e
        if block_given?
          yield(effect, e)
        else
          raise Errors::UnhandledEffectError, effect
        end
      end
    end
  end
end

require 'dry/effects/handler'
require 'dry/effects/all'
require 'dry/effects/extensions'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-effects-0.1.0.alpha2 lib/dry/effects.rb
dry-effects-0.1.0.alpha lib/dry/effects.rb