You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to find or create a macro to generate async and blocking versions from the same source code. The solution should allow both implementation to coexist, build and run if feature flags for both are enabled. It should also be possible to test both versions with the --all-features flag.
Use case
In the bdk_esplora package code is duplicated in the async_ext and blocking_ext modules.
Additional context
In the pre-1.0.0 code we used a maybe_async! macro created by @afilini but it can only create async OR block code, and for blocking it uses tokio::Runtime::block_on() so still requires the tokio dependency.
synca seems really nice and saw some comments in the blogpost was mentioning it.
One thing that concerns me is that the crate, as you've said, brand new.
However it only has 3 dependencies:
proc-macro2
quote
syn
All of these are pretty established and past maturity (^1.0) and also from dtolnay,
so I don't think that synca will give us headaches in the future.
I think we can move this to beta milestone no?
I don't think it will change the API but definitely an internal performance/refactor thing.
If this is for the beta milestone, I might want to take a look into it and see if I can come up with a PR.
Thanks for looking more into this. And yes since this shouldn't change any APIs I'll put it in the beta milestone. But if we can't get it done there we can always push it out to a 1.1 release.
The code is not entirely duplicated though :. The sync esplora uses threads while the other one doesn't. Would be interested to see if you can finangle a solution there.
Describe the enhancement
It would be nice to find or create a macro to generate async and blocking versions from the same source code. The solution should allow both implementation to coexist, build and run if feature flags for both are enabled. It should also be possible to test both versions with the
--all-features
flag.Use case
In the
bdk_esplora
package code is duplicated in theasync_ext
andblocking_ext
modules.Additional context
In the pre-1.0.0 code we used a
maybe_async!
macro created by @afilini but it can only create async OR block code, and for blocking it usestokio::Runtime::block_on()
so still requires the tokio dependency.This issue is inspired by a discussion with @storopoli and the article he shared during a PR code review: "The bane of my existence: Supporting both async and sync code in Rust".
The synca crate is relatively new but looks like it provides a good solution to this problem.
The text was updated successfully, but these errors were encountered: