Skip to content

Commit 045ebfd

Browse files
authored
Merge pull request #119 from carllerche/task-is-current
Task::is_current returns true when task is running
2 parents ad60deb + b76e8f4 commit 045ebfd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/task/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ impl Task {
148148
self.events.trigger();
149149
self.unpark.unpark();
150150
}
151+
152+
/// Returns `true` when called from within the context of the task. In
153+
/// other words, the task is currently running on the thread calling the
154+
/// function.
155+
pub fn is_current(&self) -> bool {
156+
with(|current, _| current.id == self.id)
157+
}
151158
}
152159

153160
/// Representation of a spawned future/stream.

0 commit comments

Comments
 (0)