puma/puma — pull request #110 by kenkeiter (2012-06-28 00:07:06+00:00)
Title: Allow Server#run to be optionally executed in the current thread (enabling custom threading).

This patch unobtrusively fixes Server#run so that it can be executed in the main thread. This is primarily to allow users to wrap run in whatever thread spawning mechanism they'd like to, and enables use with Celluloid by including the Celluloid module at load time,

Puma::Server.send(:include, Celluloid)

allowing supervision of the server's runloop. Note that it does NOT change the way run needs to be called, but simply allows it to be called with an additional hash arg :in_thread => false, which will start the event loop in the calling thread. For example:

server = Puma::Server.new(App)
server.add_tcp_listener('localhost', 9090)
server.run(:in_thread => false) # starts runloop in Thread#current, returning nothing.

It may also be started the old way, with no modification:

server.run