Sha256: 6277f31d3bc38110a311be6f4780f91701ab3d92cf0828fd62eb6a967527c2ef

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 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!)

        # Yield the block with the handler installed
        #
        # @api private
        def call
          @stack = Frame.stack
          yield
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-effects-0.5.0 lib/dry/effects/providers/parallel.rb