Skip to content

How to attach custom info to task? #120

Answered by shuoli84
shuoli84 asked this question in Q&A
Discussion options

You must be logged in to vote

Update:
#[track_caller] saved my day. Just learned the macro from tokio spawn and it can be chained, so I just add it to our wrapper and the spawn location works. E.g

#[track_caller]
pub fn try_spawn<T>(
    label: String,
    task: T,
) -> Result<tokio::task::JoinHandle<Option<T::Output>>, StopGuardError>
where
    T: Future + Send + 'static,
    T::Output: Send + 'static,
{
    match stop_receiver() {
        Some(stop_receiver) => Ok(tokio::spawn(start(label, stop_receiver, task))),
        None => Err(StopGuardError),
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hawkw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #118 on September 07, 2021 15:58.