Can TaskLocalFuture be public? #3256
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-task
Module: tokio/task
Is your feature request related to a problem? Please describe.
We'd like to use task locals from nameable futures (to use them with
Service
w/o boxing), however,LocalKey::scope
usesasync fn
which stands between us and the goal of being able to name futures.Describe the solution you'd like
LocalKey::scope
already constructs a hand-implemented future. It's just not exposing that to the outside but awaiting it directly. Ideally the function would just return theTaskLocalFuture
instead of awaiting it directly.I think the fact that the future is private is because of the
StaticLifetime
-trait that tokio does not want to expose, because it's used as a workaround forpin_project_lite
limitations. If we sealed that trait, however, exposing it would be fine.If you agree this is a solution I'm happy to file a PR for both tokio 0.3 and 0.2.
Describe alternatives you've considered
We can just box all our futures that add task locals to their inner futures, or wait until
impl Trait
in associated type position / async fn in traits becomes stable.Kind of moot to always keep waiting for Rust features until actually doing something, though. 😄
Additional context
Implementing
tower::Service
.The text was updated successfully, but these errors were encountered: