Class: Files::SizableIO

Inherits:
IO
  • Object
show all
Defined in:
lib/files.com/sizable_io.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pipeObject



3
4
5
6
7
8
9
# File 'lib/files.com/sizable_io.rb', line 3

def self.pipe
  r, w = super

  w.instance_variable_set(:@read_io, r)

  [ r, w ]
end

Instance Method Details

#closeObject

Raises:

  • (@with_error)


30
31
32
33
34
35
36
# File 'lib/files.com/sizable_io.rb', line 30

def close
  raise @with_error if @with_error

  super
  read_io.content_length_promise.try_set(nil)
  read_io.ready_promise.try_set(true)
end

#do_set_error(e) ⇒ Object



42
43
44
# File 'lib/files.com/sizable_io.rb', line 42

def do_set_error(e)
  read_io.with_error = e
end

#error!Object



38
39
40
# File 'lib/files.com/sizable_io.rb', line 38

def error!
  raise read_io.with_error if read_io.with_error
end

#fulfill_content_length(length) ⇒ Object



21
22
23
24
# File 'lib/files.com/sizable_io.rb', line 21

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

#ready!Object



26
27
28
# File 'lib/files.com/sizable_io.rb', line 26

def ready!
  read_io.ready_promise.execute
end

#sizeObject



11
12
13
# File 'lib/files.com/sizable_io.rb', line 11

def size
  read_io.content_length_promise.wait.value
end

#wait!(timeout = nil) ⇒ Object



15
16
17
18
19
# File 'lib/files.com/sizable_io.rb', line 15

def wait!(timeout = nil)
  read_io.ready_promise.wait(timeout)
  error!
  self
end