slack-ruby-client icon indicating copy to clipboard operation
slack-ruby-client copied to clipboard

Moving work off the main thread

Open kstole opened this issue 7 years ago • 5 comments

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?

kstole avatar Nov 16 '18 17:11 kstole

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.

dblock avatar Nov 16 '18 18:11 dblock

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.

kstole avatar Feb 01 '19 02:02 kstole

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 :)

ioquatix avatar Feb 01 '19 02:02 ioquatix

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.

ioquatix avatar Feb 01 '19 02:02 ioquatix

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 :)

dblock avatar Feb 01 '19 15:02 dblock