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

task: Add TaskLocalFuture::take_value method to the task_local #6340

Merged
merged 9 commits into from
Feb 21, 2024

Conversation

mox692
Copy link
Member

@mox692 mox692 commented Feb 12, 2024

Motivation

Try to resolve #5743.

This PR adds a method take_value to take the task local value of a TaskLocalFuture.
The LocalKey::scope() function owns the slot value and drops it, but this method will allow you to re-acquire ownership of the slot value.

Solution

Implemented method take_value for a pinned TaskLocalFuture.
Maybe it is possible to provide non-pinned api as well (pub fn take_value(&mut self) -> Option<T>), but I'm not sure if it is worth providing both.

@maminrayej maminrayej added A-tokio Area: The main tokio crate M-task Module: tokio/task labels Feb 12, 2024
@mox692 mox692 force-pushed the task_local_future_take_value branch from 10cbb3b to 61cde0f Compare February 14, 2024 16:18
tokio/src/task/task_local.rs Outdated Show resolved Hide resolved
tokio/src/task/task_local.rs Outdated Show resolved Hide resolved
tokio/src/task/task_local.rs Outdated Show resolved Hide resolved
tokio/src/task/task_local.rs Outdated Show resolved Hide resolved
tokio/src/task/task_local.rs Outdated Show resolved Hide resolved
tokio/src/task/task_local.rs Outdated Show resolved Hide resolved
mox692 and others added 6 commits February 20, 2024 01:10
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@Darksonn Darksonn merged commit 94db07b into tokio-rs:master Feb 21, 2024
75 checks passed
@mox692 mox692 deleted the task_local_future_take_value branch February 25, 2024 03:30
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 M-task Module: tokio/task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TaskLocalFuture::into_value
3 participants