Conversation
* introduce run_async in celluloid/eventmachine * introduce start_async in realtime client This is useful for mixing slack client code with a web server. Slack client itself is running asynchronously, but the web server is blocking.
|
What if we made |
|
I'd prefer smaller/more methods that accept less parameters/options. I like when code crashes on mistakes (like typos) instead of doing the wrong thing. If you mistype a method, it will crash. If you mistype an option, nothing might happen. I'd be ok with Also I prefer two methods, because it means less conditionals in the code. If option is passed, something has do decide what to do for true/false. When when it is a method, it does just one thing, and always the same thing. Here the decision lies on the one who is using the client and there are no conditionals in the code. |
|
I think we should take this opportunity to make an interface we want then. We want |
|
With this change, does it still make sense to have a separate Concurrency::Faye? |
|
@dblock will think about it. I quite liked the bang because it says there is something dangerous (like never returning). I'd be in for making The I think Concurrency::Faye still makes sense, because it has to handle starting EM reactor and start the Imho there is quite a lot of confusion in the naming (client, socket, driver, socket, ....) so at some point I'd like to rename them all to be more explicit what they do. |
|
Makes sense. I think I just don't like that Lets talk about renaming things, I agree that it's quite confusing. We should do it sooner than later because none of this stuff has been released yet. |
|
Bump @mikz. Need help? |
|
@dblock was traveling for last week so I had no chance to take a look. I might find some time this week, but would give it 50 % chance. To continue the discussion. I think the version without bang would work, but it is too close to the one with bang and has so different semantics. If there would be one with and without bang I'd expect it to have raise exception / reconnect semantics instead of async/blocking behaviour. In the future I think it should be So to reach some kind of decision I propose:
The naming does not have to be exactly like that, but I'd really suggest to have two methods like Then there would be other option, to have just one I'm more inclined to to two methods instead of two drivers, but I'm not sure why. Imho it is less cognitive overhead to reason about. |
|
I really like the multiple driver version, it uses inheritance instead of method naming and reduces the size of the API, which I think is a lot better. I think you like the initial proposal because of where the code evolved from, but if you step back and think about it less methods = less cognitive overhead and you don't have to think of this as a matrix. Thoughts? |
|
@dblock I try to prefer composition over inheritance, so I'm not so thrilled about letting inheritance solve everything. Actually, the sync version will be more duplicated code. Lets get to the code: class BaseSocket
end
class AsyncCelluloidSocket < BaseSocket
def start
async.run
end
end
class SyncCelluloidSocket < AsyncCelluloidSocket
def start
super.join
end
end
class AsyncFaye < BaseSocket
def start
run_async
end
end
class SyncFaye < AsyncFaye
def start
super.join
end
endSo the class BaseSocket
def start_blocking
start_async.join
end
end
class CelluloidSocket < BaseSocket
def start_async
async.run
end
end
class Faye < BaseSocket
def start_async
run_async
end
endImho, you'd also break Liskov substition principle when |
|
Fair enough. Bring this PR to a place where you want it merged and I will probably say "yes" :) |
eventmachine one is using faye
so Gemfile.lock does not change when you change ENV
both eventmachine and celluloid can be started asynchronously that means they won't block main thread this is still work in progress, code works, but should be restructured
|
@dblock pushed work in progress, not so happy with it as i'm finding more stuff that should be somewhere else. Will give it few refactoring treatments and see. First candidates to move are the |
There was a problem hiding this comment.
Should go into the :development group.
There was a problem hiding this comment.
yeah, didn't even want to commit it, got there by mistake
There was a problem hiding this comment.
I think Gemfile.local might work for you for this kind of stuff.
|
I like this. Mostly I think it needs some tests around |
|
Note that the build is failing with |
|
Yeah, it requires bundler 1.10 to work. How soon? I might have some time on Sunday, but not much before that. Next week should be much better. |
|
Figured it all out, my problem with the integration test was that if you're going to do an async loop you don't have a blocking thread, so you need a different way to wait for the server (via a queue) or terminate the sync loop via an explicit kill (eg. Closing in favor of https://github.com/dblock/slack-ruby-client/pull/34 |
This is useful for mixing slack client code with a web server.
Slack client itself is running asynchronously, but the web server is blocking.
Closes #28
Example: