webmachine-ruby
webmachine-ruby copied to clipboard
Please provide a non-blocking alternative to Webmachine::Adapters::Reel#run().
I've got other things that I want to do on the main thread after starting up the web interface and the call at the end to Celluloid::Actor.join(@server)
blocks. Right now I've hacked a subclass that overrides #run()
to leave that call out and provides another method to do the same thing for when I do want to wait, but I don't want to have to worry about the subclass getting out of sync with the regular code.
Perhaps move the majority of #run()
into #run_without_blocking()
, add a #join_server()
with the Celluloid call and then have #run()
invoke those two?
Maybe we could add a run! method to all adapters which have the ability to run in the background? @seancribbs @bethesque
I haven't played with Celluloid before, so I don't have any informed opinion to give on that front. Given the intent of the ! is suppose to indicate that the method modifies the underlying object, it doesn't seem appropriate here.
Celluloid is a "wrapper" around Thread and Mutex, the Reel Adapter forces the Thread in which Reel runs to run in the foreground, making it impossible to run other stuff in the foreground. This is the line which accomplishes it: https://github.com/seancribbs/webmachine-ruby/blob/master/lib/webmachine/adapters/reel.rb#L36
A Workaround is to run what you would usually run in the foreground in a Thread.
#run_in_background
or similar simply is too long a method name for me, thats all. #run!
sounded okay because it modifies what run usually does.
I double checked my assumptions, just in case, and found Matz's quote on stackoverflow.
"The bang sign means "the bang version is more dangerous than its non bang counterpart; handle with care"" -Matz
I guess it's just a matter of preference, #run_in_background
seems a perfectly fine length to me. It conveys exactly what it does (which is one of the goals of naming things), where as run!
just conveys that it's running differently to normal somehow.
But it seems that it's a pointless debate, if there's no actual code change we can make anyway?