summaryrefslogtreecommitdiff
path: root/monoio/src/task/join.rs
diff options
context:
space:
mode:
Diffstat (limited to 'monoio/src/task/join.rs')
-rw-r--r--monoio/src/task/join.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/monoio/src/task/join.rs b/monoio/src/task/join.rs
index 4f11add..f664d7b 100644
--- a/monoio/src/task/join.rs
+++ b/monoio/src/task/join.rs
@@ -9,6 +9,7 @@ use super::raw::RawTask;
/// JoinHandle can be used to wait task finished.
/// Note if you drop it directly, task will not be terminated.
+///用于等待 task 完成, 但是如果直接丢弃它, task 将不会立刻被终止
pub struct JoinHandle<T> {
raw: RawTask,
_p: PhantomData<T>,
@@ -26,6 +27,7 @@ impl<T> JoinHandle<T> {
}
/// Checks if the task associated with this `JoinHandle` has finished.
+ /// 检查与此 `JoinHandle` 关联的 task 是否已完成
pub fn is_finished(&self) -> bool {
let state = self.raw.header().state.load();
state.is_complete()
@@ -42,11 +44,13 @@ impl<T> Future for JoinHandle<T> {
// Try to read the task output. If the task is not yet complete, the
// waker is stored and is notified once the task does complete.
+ // 尝试读取 task 输出, 如果 task 还没有完成, 则存储 waker, 并在 task 完成时通知它
//
// The function must go via the vtable, which requires erasing generic
// types. To do this, the function "return" is placed on the stack
// **before** calling the function and is passed into the function using
// `*mut ()`.
+ // 函数必须通过 vtable, 这需要擦除泛型类型, 为此, 函数 "返回" 被放置在栈上, 在调用函数之前, 并使用 `*mut ()` 将其传递到函数中
//
// Safety:
//
@@ -59,8 +63,10 @@ impl<T> Future for JoinHandle<T> {
}
}
+// drop joinhandle
impl<T> Drop for JoinHandle<T> {
fn drop(&mut self) {
+ // 如果不能快速丢弃, 则调用慢速丢弃
if self.raw.header().state.drop_join_handle_fast().is_ok() {
return;
}