summaryrefslogtreecommitdiffstats
path: root/tokio/src/executor/thread_pool/join.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/executor/thread_pool/join.rs')
-rw-r--r--tokio/src/executor/thread_pool/join.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/tokio/src/executor/thread_pool/join.rs b/tokio/src/executor/thread_pool/join.rs
new file mode 100644
index 00000000..e066882a
--- /dev/null
+++ b/tokio/src/executor/thread_pool/join.rs
@@ -0,0 +1,42 @@
+use crate::executor::park::Unpark;
+use crate::executor::task;
+use crate::executor::thread_pool::Shared;
+
+use std::fmt;
+use std::future::Future;
+use std::pin::Pin;
+use std::task::{Context, Poll};
+
+/// An owned permission to join on a task (await its termination).
+pub struct JoinHandle<T> {
+ task: task::JoinHandle<T, Shared<Box<dyn Unpark>>>,
+}
+
+impl<T> JoinHandle<T>
+where
+ T: Send + 'static,
+{
+ pub(super) fn new(task: task::JoinHandle<T, Shared<Box<dyn Unpark>>>) -> JoinHandle<T> {
+ JoinHandle { task }
+ }
+}
+
+impl<T> Future for JoinHandle<T>
+where
+ T: Send + 'static,
+{
+ type Output = task::Result<T>;
+
+ fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
+ Pin::new(&mut self.task).poll(cx)
+ }
+}
+
+impl<T> fmt::Debug for JoinHandle<T>
+where
+ T: fmt::Debug,
+{
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt.debug_struct("JoinHandle").finish()
+ }
+}