@@ -47,6 +47,28 @@ impl RuntimeMetrics {
47
47
self . handle . inner . num_workers ( )
48
48
}
49
49
50
+ /// Returns the current number of alive tasks in the runtime.
51
+ ///
52
+ /// This counter increases when a task is spawned and decreases when a
53
+ /// task exits.
54
+ ///
55
+ /// # Examples
56
+ ///
57
+ /// ```
58
+ /// use tokio::runtime::Handle;
59
+ ///
60
+ /// #[tokio::main]
61
+ /// async fn main() {
62
+ /// let metrics = Handle::current().metrics();
63
+ ///
64
+ /// let n = metrics.num_alive_tasks();
65
+ /// println!("Runtime has {} alive tasks", n);
66
+ /// }
67
+ /// ```
68
+ pub fn num_alive_tasks ( & self ) -> usize {
69
+ self . handle . inner . num_alive_tasks ( )
70
+ }
71
+
50
72
cfg_unstable_metrics ! {
51
73
52
74
/// Returns the number of additional threads spawned by the runtime.
@@ -81,28 +103,6 @@ impl RuntimeMetrics {
81
103
self . num_alive_tasks( )
82
104
}
83
105
84
- /// Returns the current number of alive tasks in the runtime.
85
- ///
86
- /// This counter increases when a task is spawned and decreases when a
87
- /// task exits.
88
- ///
89
- /// # Examples
90
- ///
91
- /// ```
92
- /// use tokio::runtime::Handle;
93
- ///
94
- /// #[tokio::main]
95
- /// async fn main() {
96
- /// let metrics = Handle::current().metrics();
97
- ///
98
- /// let n = metrics.num_alive_tasks();
99
- /// println!("Runtime has {} alive tasks", n);
100
- /// }
101
- /// ```
102
- pub fn num_alive_tasks( & self ) -> usize {
103
- self . handle. inner. alive_tasks_count( )
104
- }
105
-
106
106
/// Returns the number of idle threads, which have spawned by the runtime
107
107
/// for `spawn_blocking` calls.
108
108
///
0 commit comments