File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11module Cramp
2+ # All the usual Cramp::Action stuff. But the request is terminated as soon as render() is called.
23 class LongPolling < Abstract
34 include PeriodicTimer
45 include KeepConnectionAlive
You can’t perform that action at this time.
0 commit comments