Class: Kronk::Player::Stream

Inherits:
Kronk::Player show all
Defined in:
lib/kronk/player/stream.rb

Overview

Outputs Player results as a stream of Kronk outputs in chunked form, each chunk being one response and the number of octets being expressed in hexadecimal form.

out   = Player::StreamOutput.new

io1   = StringIO.new "this is the first chunk"
io2   = StringIO.new "this is the rest"

kronk = Kronk.new
kronk.request io1
out.result kronk
#=> "17\r\nthis is the first chunk\r\n"

kronk.request io2
out.result kronk
#=> "10\r\nthis is the rest\r\n"

Note: This output class will not render errors.

Instance Attribute Summary

Attributes inherited from Kronk::Player

#concurrency, #input, #mutex, #qps

Attributes inherited from QueueRunner

#count, #number, #queue, #reader_thread, #threads

Instance Method Summary collapse

Methods inherited from Kronk::Player

#compare, #from_io, #initialize, new_type, #request, #run, #trigger_result

Methods inherited from QueueRunner

#concurrently, #finish, #finished?, #initialize, #kill, #on, #periodically, #start_input!, #stop_input!, #trigger, #until_finished, #yield_queue_item

Constructor Details

This class inherits a constructor from Kronk::Player

Instance Method Details

#completedObject



47
48
49
50
51
# File 'lib/kronk/player/stream.rb', line 47

def completed
  $stdout << "0\r\n\r\n"
  $stdout.flush
  true
end

#result(kronk) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kronk/player/stream.rb', line 26

def result kronk
  output =
    if kronk.diff
      kronk.diff.formatted

    elsif kronk.response
      kronk.response.stringify
    end

  return unless output && !output.empty?

  @mutex.synchronize do
    $stdout << "#{"%X" % output.length}\r\n"
    $stdout << output
    $stdout << "\r\n"
  end

  output
end