Skip to content
Newer
Older
100644 37 lines (27 sloc) 638 Bytes
48ec74e @lifo Add an example for long polling using Cramp::LongPolling
authored
1 require "rubygems"
2 require "bundler"
3 Bundler.setup(:default, :example)
4
5 require 'cramp'
6 require 'thin'
7
8 class LazyController < Cramp::LongPolling
9 on_start :init_limit
10 periodic_timer :check_limit, :every => 1
11
12 def init_limit
13 @limit = 0
14 end
15
16 def check_limit
17 @limit += 1
18
19 if @limit > 20
20 puts "And the wait is over !!!"
21
22 # Send back a response to the client. Terminate the request.
23 render "Hello World!"
24 else
25 puts "You must wait"
26 end
27 end
28
29 def respond_with
30 [200, {'Content-Type' => 'text/plain'}]
31 end
32
33 end
34
35 # bundle exec thin -V -R examples/long_poll.ru start
36 run LazyController
Something went wrong with that request. Please try again.