Sha256: 7409b5ed99cb0584dc8dbbc352b64d74d3f6050c9a554e21d29cdfc746e00c93

Contents?: true

Size: 764 Bytes

Versions: 1

Compression:

Stored size: 764 Bytes

Contents

module Files
  class SizableIO < IO
    def self.pipe
      r, w = super

      w.instance_variable_set(:@read_io, r)

      [ r, w ]
    end

    def size
      read_io.content_length_promise.wait.value
    end

    def fulfill_content_length(length)
      read_io.content_length = length
      read_io.content_length_promise.execute
    end

    def close
      raise @with_error if @with_error
      super
      read_io.content_length_promise.try_set(nil)
    end

    def set_error(e)
      read_io.with_error = e
    end

    protected

    attr_accessor :content_length, :with_error

    def content_length_promise
      @content_length_promise ||= Concurrent::Promise.new { content_length }
    end

    def read_io
      @read_io || self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
files.com-1.0.178 lib/files.com/sizable_io.rb