Class: Arcp::Runtime::JobContext::ChunkWriter Private
- Inherits:
-
Object
- Object
- Arcp::Runtime::JobContext::ChunkWriter
- Defined in:
- lib/arcp/runtime/job_context.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #close ⇒ Object private
-
#initialize(ctx:, encoding:, result_id:) ⇒ ChunkWriter
constructor
private
A new instance of ChunkWriter.
- #totals ⇒ Object private
- #write(chunk, more: true) ⇒ Object private
Constructor Details
#initialize(ctx:, encoding:, result_id:) ⇒ ChunkWriter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ChunkWriter.
132 133 134 135 136 137 138 139 |
# File 'lib/arcp/runtime/job_context.rb', line 132 def initialize(ctx:, encoding:, result_id:) @ctx = ctx @encoding = encoding @result_id = result_id @seq = 0 @bytes = 0 @closed = false end |
Instance Method Details
#close ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
157 158 159 160 161 |
# File 'lib/arcp/runtime/job_context.rb', line 157 def close return if @closed @closed = true end |
#totals ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
163 |
# File 'lib/arcp/runtime/job_context.rb', line 163 def totals = { bytes: @bytes, chunks: @seq, result_id: @result_id } |
#write(chunk, more: true) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/arcp/runtime/job_context.rb', line 141 def write(chunk, more: true) raise Arcp::Errors::ProtocolViolation, 'stream closed' if @closed data = case @encoding when 'base64' then Base64.strict_encode64(chunk) else chunk.dup.force_encoding('UTF-8') end @bytes += chunk.bytesize body = Arcp::Job::EventBody::ResultChunk.new( result_id: @result_id, chunk_seq: @seq, data: data, encoding: @encoding, more: more ) @ctx.emit(kind: Arcp::Job::EventKind::RESULT_CHUNK, body: body) @seq += 1 end |