Skip to content

Instantly share code, notes, and snippets.

@jimsynz
Created May 14, 2012 22:26
Show Gist options
  • Save jimsynz/2697843 to your computer and use it in GitHub Desktop.
Save jimsynz/2697843 to your computer and use it in GitHub Desktop.
class LongPoller
def self.go(&block)
self.new(block)
end
def initialize(block)
@block = block
end
def each(&sender)
EM.defer do
sender.call @block.call
end
end
end
````ruby
class ProjectsController < ApplicationController
def create
self.status = 200
self.content_type = 'application/json; charset=utf-8'
self.response_body = LongPoller.go do
# Can take up to 80 seconds
Project.new(params[:project]).to_json
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment