-
Notifications
You must be signed in to change notification settings - Fork 28
Async/await and FDB 6.1 support #135
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
Comments
Very cool -- if you have the time a PR would be great |
Hey @dae, funny timing! I'd similarly been working on converting the library to async/await (schallert/foundationdb-rs#1) over the past few weeks before I saw you were doing the same. It seems like our implementations are pretty similar with a few differences. One thing I noticed from the
My understanding is that this allows a future to be moved between executors. To that end I'm using an Would you be interesting in us comparing our approaches and trying to pull in the best of both implementations? Very cool to see someone else tackling async/await for this library :) |
Happy to collaborate! A couple of preliminary thoughts:
|
Sorry, ignore the earlier box comment - of course we also need a reference in poll(). The tests in your branch are nicer, as you've rewritten more of the code to use await instead of keeping the existing combinators in place as I did. In terms of which branch makes a better starting point, perhaps the maintainers could chime in? If dropping pre-6.1 compatibility or accepting async closures is a dealbreaker, that may make the decision for us :-) |
Sorry for the delay here! Yeah, my adventures down the Arc path came after some painful segfaults when just using a Box. I hadn't realized there was a way to implement |
One thing that bothers me about the current db.transact() implementation is that it seems to require cloning the transaction object and other owned objects, like: #[test]
fn test_transact_via_db() {
common::setup_static();
let s = String::from("test");
let db = Database::new(foundationdb::default_config_path()).unwrap();
block_on(db.transact(|trx| {
let trx = trx.clone();
let s = s.clone();
async move {
let trx = trx.clone();
trx.set(s.as_bytes(), s.as_bytes());
Ok(())
}
})).unwrap();
} I wasn't able to figure out a way to modify db.transact() or the calling code to avoid the cloning, but my knowledge of lifetimes is limited, so I may be missing something. An alternative approach that does seem to work is to move transact() into the transaction object instead, which allows for the following: #[test]
fn test_transact_via_trx() {
common::setup_static();
let s = String::from("test");
let db = Database::new(foundationdb::default_config_path()).unwrap();
let trx = db.create_trx().unwrap();
block_on(trx.transact(|| async {
trx.set(s.as_bytes(), s.as_bytes());
Ok(())
})).unwrap();
} Any thoughts/ideas? |
I wrote my own vision of what foundationdb async/await can be: #143 I had some issue typing transact the way I wanted and I hope future rustc version will allow to remove the |
I've ported this library to edition 2018, futures 0.3 and foundationdb 6.1 as a learning exercise. All the tests pass, and the bindingtester does not report any problems.
As the async changes will require a version number bump, I thought it made sense to make the breaking changes required to support FDB 6.1 at the same time, instead of going to the extra trouble of trying to support both APIs at once (#124)
If you'd like me to send a pull request let me know. In the mean time users can try it out on my branch: https://github.com/dae/foundationdb-rs/tree/futures0.3-rebased
The text was updated successfully, but these errors were encountered: