Sha256: 7946935f8414e8b295388243777e7ad9160b1832947a2a360a63502325986ba5

Contents?: true

Size: 771 Bytes

Versions: 3

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

require "concurrent/promise"

module Dry
  module Effects
    module Providers
      class Parallel < Provider[:parallel]
        include ::Dry::Equalizer(:executor, inspect: false)

        option :executor, default: -> { :io }

        attr_reader :stack

        def par
          stack = self.stack.dup
          proc do |&block|
            ::Concurrent::Promise.execute(executor: executor) do
              Frame.spawn_fiber(stack, &block)
            end
          end
        end

        def join(xs)
          xs.map(&:value!)
        end

        # Yield the block with the handler installed
        #
        # @api private
        def call
          @stack = Frame.stack
          yield
        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/parallel.rb
dry-effects-0.4.0 lib/dry/effects/providers/parallel.rb
dry-effects-0.3.1 lib/dry/effects/providers/parallel.rb