Sha256: b9a093ebfce792531f603c4efef104272dfca78cef52186a4149a43247db2564

Contents?: true

Size: 637 Bytes

Versions: 2

Compression:

Stored size: 637 Bytes

Contents

# frozen_string_literal: true

require 'dry/effects/provider'

module Dry
  module Effects
    module Providers
      class Async < Provider[:async]
        option :tasks, default: -> { ::Hash.new }

        include Dry::Equalizer(:tasks)

        attr_reader :stack

        def async(block)
          @tasks[block] = block
        end

        def await(task)
          Frame.spawn_fiber(stack, &@tasks.delete(task))
        end

        # Yield the block with the handler installed
        #
        # @api private
        def call(stack)
          @stack = stack
          super
          nil
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-effects-0.1.1 lib/dry/effects/providers/async.rb
dry-effects-0.1.0 lib/dry/effects/providers/async.rb