-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0627957
commit 7e70a49
Showing
4 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub mod fs; | ||
#[cfg(feature = "tracing")] | ||
pub mod tokio; | ||
#[cfg(feature = "tracing")] | ||
pub mod tracing; | ||
#[cfg(feature = "version")] | ||
pub mod version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
|
||
use tokio::task::JoinError; | ||
|
||
/// A wrapper around a [tokio::task::JoinHandle] that attaches a name. | ||
/// | ||
/// This enables a parent task to await all children simultaneously but still | ||
/// determine what child has exited for logging/diagnosis purposes. | ||
#[derive(Debug)] | ||
pub struct NamedTask<Ret = (), Id = String> | ||
where | ||
Id: Clone + Unpin, | ||
{ | ||
task: Pin<Box<tokio::task::JoinHandle<Ret>>>, | ||
id: Id, | ||
} | ||
|
||
impl<R, I> NamedTask<R, I> | ||
where | ||
I: Clone + Unpin, | ||
{ | ||
pub fn new(task: tokio::task::JoinHandle<R>, id: I) -> Self { | ||
NamedTask { task: Box::pin(task), id } | ||
} | ||
} | ||
|
||
impl<R, I> Future for NamedTask<R, I> | ||
where | ||
I: Clone + Unpin, | ||
{ | ||
type Output = (I, Result<R, JoinError>); | ||
|
||
fn poll( | ||
mut self: Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Self::Output> { | ||
self.task.as_mut().poll(cx).map(|v| (self.id.clone(), v)) | ||
} | ||
} |