Sha256: 57a4713f27eb7b29ce361a2b67018caf92a43acac8eaa8aecaa6c601b47a344b

Contents?: true

Size: 525 Bytes

Versions: 1

Compression:

Stored size: 525 Bytes

Contents

# frozen_string_literal: true

module Pull
  class Drain
    DEFAULT_DONE_CALLBACK = -> () {
      puts "DONE"
    }

    def initialize(&block)
      @block = block
      @continuing = true
    end

    def call(read, done = DEFAULT_DONE_CALLBACK)
      raise TypeError unless read.respond_to?(:call)
      while @continuing
        return done.() && break if !@continuing
        @continuing = read.(nil, -> (value) {
          block.call(value)
        })
      end
    end

    private

    attr_reader :block
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pull_stream-1.0.0 lib/pull/sink/drain.rb