Class: Sinatra::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudflare_workers/stream.rb

Instance Method Summary collapse

Instance Method Details

#stream(keep_open = false, &block) ⇒ Object

Re-open to override. We keep the signature compatible with upstream (‘stream(keep_open = false, &block)`) but internally route through Cloudflare::SSEStream. Upstream’s ‘Stream` class is not used on Workers (no EventMachine / Thread pool).



307
308
309
310
311
312
313
314
# File 'lib/cloudflare_workers/stream.rb', line 307

def stream(keep_open = false, &block)
  ctx = env['cloudflare.ctx']
  ::Cloudflare::SSEStream.new(
    headers: { 'content-type' => 'text/plain; charset=utf-8' },
    ctx: ctx,
    &block
  )
end