Skip to content
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

Can TaskLocalFuture be public? #3256

Closed
NeoLegends opened this issue Dec 11, 2020 · 0 comments · Fixed by #3273
Closed

Can TaskLocalFuture be public? #3256

NeoLegends opened this issue Dec 11, 2020 · 0 comments · Fixed by #3273
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-task Module: tokio/task

Comments

@NeoLegends
Copy link
Contributor

NeoLegends commented Dec 11, 2020

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 uses async 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 the TaskLocalFuture 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 for pin_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.

@NeoLegends NeoLegends added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Dec 11, 2020
@Darksonn Darksonn added the M-task Module: tokio/task label Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-task Module: tokio/task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants