Moving work off the main thread
I haven't had time to contribute recently but I've been watching the Slack disconnects issues carefully as my bot is now disconnecting almost every night. I understand switching to async may be advantageous. One of the things I used heavily before was Celluloid.defer to prevent responding to commands blocking the bot from responding to other commands. This may be a question better suited for @ioquatix but is there an appropriate replacement for this using async?
Generally I would like to include clear recommendation in README for this and possible default code that responds to commands into a defer-like behavior by default.
Some discussion of this in https://github.com/socketry/async-websocket/issues/2
Seems like Celluloid.defer uses a separate thread to make the block asynchronous and async doesn't have an exact match. Async.run do |task| can be used and then task.sleep doesn't block and HTTP calls can be made asynchronous with async/http/faraday but not a simple cut/paste solution.
Seems like Celluloid.defer uses a separate thread to make the block asynchronous and async doesn't have an exact match.
I gave you an implementation for exactly that on the linked ticket :)
By the way, using a thread/defer defeats the entire purpose of being asynchronous, so I don't think it should be the default. It should be for use case where no suitable alternative exists. For example, if you use Celluloid::IO, some IO becomes non-blocking. There isn't much upstream support, but that's not the case with async, where we already support fully asynchronous Postgres, Redis, HTTP, etc.
I'd really appreciate if someone could clarify all this in the README, especially for async noobs like me. I just want to know what I am supposed to do :)