stream multiple body using async sinatra

后端 未结 2 572
萌比男神i
萌比男神i 2020-12-29 17:10

I would like start a long poll request from javascript which is fine and i expect my ruby prog to stream multiple body sections to the javascript. Why doesn the following (p

2条回答
  •  萌比男神i
    2020-12-29 17:36

    It appears in the example below that you need an EventMachine event to trigger the sending of the multiple bodies. Also see this previous answer as well.

    require 'sinatra/async'
    
     class AsyncTest < Sinatra::Base
       register Sinatra::Async
    
       aget '/' do
         body "hello async"
       end
    
       aget '/delay/:n' do |n|
         EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
       end
    
     end
    

提交回复
热议问题