Description
I maintain some libraries that have sync and async users. The async users wrap calls in spawn_blocking
, which works, but isn't ergonomic and may be suboptimal. maybe_async
looks like it could potentially be (part of) an alternative approach.
If I read the docs right, maybe_async
can support both sync and async users, but by using a cargo feature, it can't support both in the same program. If the library gets used in multiple places in the same program, and one of them enables is_sync
, it would break the other places that need async.
It seems like it would be useful to have a macro that expands to both sync and async, using different names, so that they can coexist. For example,
#[maybe_async::both]
async fn foo() -> bool {
true
}
might expand to:
#[cfg(feature = "async")]
async fn async_foo() -> bool {
true
}
#[cfg(feature = "sync")]
fn sync_foo() -> bool {
true
}
so that users can call whichever form they need by name (though I'm not attached to the particular naming convention here).