-
-
Save zotherstupidguy/c140be3f510569d39ea20ddf8dca3fe7 to your computer and use it in GitHub Desktop.
yes WEB API (Ruby + Sinatra/Streaming)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| require 'sinatra' | |
| require 'sinatra/streaming' | |
| set server: 'thin', connections: [] | |
| th = Thread.new{ | |
| while true | |
| puts "currently connection: #{settings.connections.size}" | |
| settings.connections.each{ |e| | |
| e << "yes\n" | |
| } | |
| sleep 1 | |
| end | |
| } | |
| get '/' do | |
| stream :keep_open do |out| | |
| out.callback{ settings.connections.delete(out) } | |
| out.errback{ settings.connections.delete(out) } | |
| settings.connections << out | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment