Class: Pytty::Daemon::Api::Chunk

Inherits:
Object
  • Object
show all
Defined in:
lib/pytty/daemon/api/chunk.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pytty/daemon/api/chunk.rb', line 9

def call(env)
  task = Async::Task.current
  body = Async::HTTP::Body::Writable.new
  task.async do |task|
    10.times do
      body.write "hello"
      task.sleep 0.5
    end
  rescue Exception => ex
    p ex
  ensure
    body.close
  end

  [200, {'content-type' => 'text/html; charset=utf-8'}, body]
end