webmachine-ruby icon indicating copy to clipboard operation
webmachine-ruby copied to clipboard

Please provide a non-blocking alternative to Webmachine::Adapters::Reel#run().

Open clonezone opened this issue 10 years ago • 4 comments

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?

clonezone avatar Feb 09 '15 18:02 clonezone

Maybe we could add a run! method to all adapters which have the ability to run in the background? @seancribbs @bethesque

Asmod4n avatar Feb 09 '15 20:02 Asmod4n

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.

bethesque avatar Feb 10 '15 03:02 bethesque

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.

Asmod4n avatar Feb 11 '15 13:02 Asmod4n

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?

bethesque avatar Feb 11 '15 20:02 bethesque