Permalink
Browse files

Pre-alpha. Fit for testing only.

  • Loading branch information...
kindkid committed Mar 20, 2012
0 parents commit 40b1e640455da6683f47c1a08440a59e865ae79d
Showing with 142 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +1 −0 .rvmrc
  3. +4 −0 Gemfile
  4. +25 −0 README
  5. +12 −0 Rakefile
  6. +29 −0 endless.gemspec
  7. +14 −0 lib/endless.rb
  8. +37 −0 lib/endless/app.rb
  9. +3 −0 lib/endless/version.rb
  10. +5 −0 tasks/console.rake
  11. +4 −0 tasks/environment.rake
  12. +4 −0 tasks/server.rake
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.3@endless --create
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in endless.gemspec
+gemspec
25 README
@@ -0,0 +1,25 @@
+Endless
+=======
+A tiny webapp for generating an endless stream of data in an HTTP response.
+
+
+Installation
+============
+
+ gem install endless
+
+
+Usage
+=====
+
+ rake server[5678]
+
+ curl -s http://localhost:5678/endless | head -c 100
+
+Caveats
+=======
+
+Pre-alpha software. Useful for testing purposes only.
+
+Currently, I think the server just keeps streaming a response even after the
+client disconnects, until you kill the server. Pull requests welcome!
@@ -0,0 +1,12 @@
+require "bundler/gem_tasks"
+
+require 'bundler/setup'
+Bundler.require(:default)
+
+Dir['tasks/*.rake'].sort.each { |task| load task }
+
+# Add rake tasks from selected gems
+gem_names = []
+gem_names.each do |gem_name|
+ Dir[File.join(Gem.searcher.find(gem_name).full_gem_path, '**', '*.rake')].each{|rake_file| load rake_file }
+end
@@ -0,0 +1,29 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "endless/version"
+
+Gem::Specification.new do |s|
+ s.name = "endless"
+ s.version = Endless::VERSION
+ s.authors = ["Chris Johnson"]
+ s.email = ["chris@kindkid.com"]
+ s.homepage = "https://github.com/kindkid/endless"
+ s.summary = "A tiny webapp for generating an endless stream of data in an HTTP response."
+ s.description = s.summary
+
+ s.rubyforge_project = "endless"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_runtime_dependency 'async_sinatra', '~> 1.0.0'
+ s.add_runtime_dependency 'thin', '~> 1.3.1'
+ s.add_development_dependency "rspec", "~> 2.9.0"
+ s.add_development_dependency "simplecov", "~> 0.6.1"
+ s.add_development_dependency("rb-fsevent", "~> 0.9.0") if RUBY_PLATFORM =~ /darwin/i
+ s.add_development_dependency "guard", "~> 1.0.1"
+ s.add_development_dependency "guard-bundler", "~> 0.1.3"
+ s.add_development_dependency "guard-rspec", "~> 0.6.0"
+end
@@ -0,0 +1,14 @@
+require "endless/version"
+
+tried_with_rubygems = false
+begin
+ require 'sinatra/async'
+ require 'thin'
+rescue => e
+ raise if tried_with_rubygems
+ tried_with_rubygems = true
+ require 'rubygems'
+ retry
+end
+
+require 'endless/app'
@@ -0,0 +1,37 @@
+module Endless
+ class App < Sinatra::Base
+ register Sinatra::Async
+
+ class DataStream
+ include EventMachine::Deferrable
+
+ def stream(data)
+ @block.call(data)
+ end
+
+ def each(&block)
+ @block = block
+ end
+ end
+
+ def randomLetters(length)
+ s = []
+ length.times do
+ s << 97+rand(26)
+ end
+ s.pack('c' * s.size)
+ end
+
+ aget '/endless' do
+ out = DataStream.new
+ body(out)
+ EM.next_tick do
+ timer = EM.add_periodic_timer(0.001) do
+ s = randomLetters(8191)
+ s << "\n"
+ out.stream(s)
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module Endless
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,5 @@
+desc "Open development console"
+task :console do
+ puts "Loading development console..."
+ system "irb -r #{File.join('.', 'lib', 'endless')}"
+end
@@ -0,0 +1,4 @@
+desc "Load the environment"
+task :environment do
+ require File.expand_path('../../lib/endless', __FILE__)
+end
@@ -0,0 +1,4 @@
+desc "Run the server"
+task :server, [:port] => :environment do |t, args|
+ Endless::App.run! :port => (args[:port] || 5678)
+end

0 comments on commit 40b1e64

Please sign in to comment.