-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checking a Promise without blocking? #5
Comments
I think your best option in such cases is to spawn a new thread and synchronize using channels. The RPC system was designed with green threads in mind. Now that libgreen is gone, I think we may need to go back and revisit some assumptions. |
It looks like |
I got a bit of a draft implementation here but I think, as you discussed, it might be better to rethink things with syncbox or mio. |
@dwrensha Any news on this? |
I'm okay with adding something like your Longer term, we clearly do need to rework our concurrency strategy. This is going to be a rather big project, and a lot of the interfaces will change. I see at least two promising approaches for getting started on this: we could port the KJ async library to Rust, or we could build off of mio/syncbox. I am personally partial to KJ because I'm familiar with it and it has proven to work well for capnproto-c++. A big difference between KJ and mio is that a KJ event loop is single-threaded, so it needs to worry less about atomic operations and synchronization. The flip side is that achieving actual parallelism with KJ can be a bit cumbersome. Tradeoffs abound. |
It looks like |
@carllerche have you looked at KJ-style promises? |
I am not super familiar with KJ-style promises, but they are compared to JS promises. Syncbox promises (which I plan on breaking out to a dedicated lib), are primarily async, but are able to block waiting for the value. They work with one thread or with many (they are thread safe and can be used to send values across threads). I'm pretty sure that they would support whatever you need, if not let me know what is missing. |
Update: I've started playing around with porting KJ to Rust. Working name: GJ. https://github.com/dwrensha/gj Looks like a big difference between GJ promises and Eventual futures is going to be that |
It would be fine to remove the default |
@carllerche: I see that pub fn map<F, U>(self, f: F) -> Future<U, E>
where F: FnOnce(T) -> U + Send + 'static,
U: Send + 'static Are you saying that this could be amended to the following? pub fn map<F, U>(self, f: F) -> Future<U, E>
where F: FnOnce(T) -> U + 'static,
U: 'static This is important for my use case because I think I'll very often want to share |
So yeah, after thinking about it for a while, I think you are correct in that this is analogous to The flip side is that the these futures won't be able to be sent across threads, which is something that I would have hoped to be able to do w/ this. Hopefully one day we will get HKT and I can update Eventual for this case. |
This is fixed in the 0.6 release, which uses GJ: https://dwrensha.github.io/capnproto-rust/2016/01/11/async-rpc.html . You can now collect the results with |
Woo! Go Drew! |
@Hoverbear are you still confusing me with @zarvox? :) |
We did meet at a Rust Meetup once. @Hoverbear has sweet business cards. :) |
@dwrensha David! Sigh.... Sorry. |
I haven't quite figured out how to create a "barrier" to wait for multiple requests.
Something like this:
Works fine for a single RPC. However because of
wait()
I'm not sure how to approach waiting on the results of multiple RPC calls without using extra threads. I don't see a sort ofhas_responded()
type functionality. Do you have a suggestion?The text was updated successfully, but these errors were encountered: