class Pull::Take

Public Class Methods

new(limit) click to toggle source
# File lib/pull/through/take.rb, line 5
def initialize(limit)
  @limit = limit
  @index = 0
end

Public Instance Methods

call(read) click to toggle source
# File lib/pull/through/take.rb, line 10
def call(read)
  -> (finish, callback) {
    if finish
      on_abort.()
      return nil
    end

    read.(nil, -> (value) {
      return nil if @index >= @limit
      callback.(value)
      @index += 1
    })
  }
end