Class: FastSend::NaiveEach

Inherits:
Struct
  • Object
show all
Defined in:
lib/fast_send.rb

Overview

Gets used as a response body wrapper if the server does not support Rack hijacking. The wrapper will be automatically applied by FastSend and will also ensure that all the callbacks get executed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#abortedObject

Returns the value of attribute aborted

Returns:

  • (Object)

    the current value of aborted



55
56
57
# File 'lib/fast_send.rb', line 55

def aborted
  @aborted
end

#body_with_each_fileObject

Returns the value of attribute body_with_each_file

Returns:

  • (Object)

    the current value of body_with_each_file



55
56
57
# File 'lib/fast_send.rb', line 55

def body_with_each_file
  @body_with_each_file
end

#cleanupObject

Returns the value of attribute cleanup

Returns:

  • (Object)

    the current value of cleanup



55
56
57
# File 'lib/fast_send.rb', line 55

def cleanup
  @cleanup
end

#completeObject

Returns the value of attribute complete

Returns:

  • (Object)

    the current value of complete



55
56
57
# File 'lib/fast_send.rb', line 55

def complete
  @complete
end

#errorObject

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



55
56
57
# File 'lib/fast_send.rb', line 55

def error
  @error
end

#sentObject

Returns the value of attribute sent

Returns:

  • (Object)

    the current value of sent



55
56
57
# File 'lib/fast_send.rb', line 55

def sent
  @sent
end

#startedObject

Returns the value of attribute started

Returns:

  • (Object)

    the current value of started



55
56
57
# File 'lib/fast_send.rb', line 55

def started
  @started
end

Instance Method Details

#eachObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fast_send.rb', line 56

def each
  written = 0
  started.call(0)
  body_with_each_file.each_file do | file |
    while data = file.read(64 * 1024)
      written += data.bytesize
      yield(data)
      sent.call(data.bytesize, written)
    end
  end
  complete.call(written)
rescue *CLIENT_DISCONNECTS => e
  aborted.call(e)
rescue Exception => e
  aborted.call(e)
  error.call(e)
  raise e
ensure
  cleanup.call(written)
end