Sha256: d412a772a3d543a66d64c89551fd5dc3c1d94713b642600b04d79645c7caf1ff

Contents?: true

Size: 830 Bytes

Versions: 4

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

require 'concurrent/promise'
require 'dry/effects/provider'
require 'dry/effects/frame'

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

4 entries across 4 versions & 1 rubygems

Version Path
dry-effects-0.1.5 lib/dry/effects/providers/parallel.rb
dry-effects-0.1.4 lib/dry/effects/providers/parallel.rb
dry-effects-0.1.3 lib/dry/effects/providers/parallel.rb
dry-effects-0.1.2 lib/dry/effects/providers/parallel.rb