@@ -202,34 +202,6 @@ pub trait FutureExt {
202202 self ,
203203 token : CancellationToken ,
204204 ) -> CancellationFuture < Self :: Future , Ready < ( ) > > ;
205-
206- /// Consumes the future, returning a new future that records the metrics of
207- /// the inner future's async task execution.
208- ///
209- /// # Example
210- ///
211- /// ```rust
212- /// use {future::FutureExt, metrics::OtelTaskMetricsRecorder, std::time::Duration};
213- ///
214- /// # async fn example() {
215- /// let recorder = OtelTaskMetricsRecorder::new("custom_task").with_name("specific_task_name");
216- ///
217- /// async {
218- /// tokio::time::sleep(Duration::from_millis(500)).await;
219- /// }
220- /// .with_metrics(recorder)
221- /// .await
222- /// # }
223- ///
224- /// # #[tokio::main]
225- /// # async fn main() {
226- /// # example().await;
227- /// # }
228- /// ```
229- #[ cfg( feature = "metrics" ) ]
230- fn with_metrics < R > ( self , recorder : R ) -> metrics:: TaskMetricsFuture < Self :: Future , R >
231- where
232- R : metrics:: TaskMetricsRecorder ;
233205}
234206
235207pub trait StaticFutureExt {
@@ -248,7 +220,7 @@ pub trait StaticFutureExt {
248220 /// tokio::time::sleep(Duration::from_millis(500)).await;
249221 /// 42
250222 /// }
251- /// .spawn("" );
223+ /// .spawn();
252224 ///
253225 /// assert!(matches!(join_handle.await, Ok(42)));
254226 /// # }
@@ -258,15 +230,7 @@ pub trait StaticFutureExt {
258230 /// # example().await;
259231 /// # }
260232 /// ```
261- #[ cfg( feature = "metrics" ) ]
262- fn spawn ( self , name : & ' static str ) -> JoinHandle < <Self :: Future as Future >:: Output > ;
263-
264- /// Same as [`StaticFutureExt::spawn`], but it won't monitor long running
265- /// futures.
266- ///
267- /// Use this only if your future is expected to be long running (ex.
268- /// singleton).
269- fn spawn_and_forget ( self ) -> JoinHandle < <Self :: Future as Future >:: Output > ;
233+ fn spawn ( self ) -> JoinHandle < <Self :: Future as Future >:: Output > ;
270234}
271235
272236impl < T > FutureExt for T
@@ -292,14 +256,6 @@ where
292256 on_cancel : ready ( ( ) ) ,
293257 }
294258 }
295-
296- #[ cfg( feature = "metrics" ) ]
297- fn with_metrics < R > ( self , recorder : R ) -> metrics:: TaskMetricsFuture < Self :: Future , R >
298- where
299- R : metrics:: TaskMetricsRecorder ,
300- {
301- metrics:: TaskMetricsFuture :: new ( self , recorder)
302- }
303259}
304260
305261impl < T > StaticFutureExt for T
@@ -309,19 +265,12 @@ where
309265{
310266 type Future = T ;
311267
312- #[ cfg( feature = "metrics" ) ]
313- fn spawn ( self , name : & ' static str ) -> JoinHandle < <Self :: Future as Future >:: Output > {
314- static METRICS : metrics:: TaskMetrics = metrics:: TaskMetrics :: new ( "spawned_task" ) ;
315-
316- tokio:: spawn ( self . with_metrics ( METRICS . with_name ( name) ) )
317- }
318-
319- fn spawn_and_forget ( self ) -> JoinHandle < <Self :: Future as Future >:: Output > {
268+ fn spawn ( self ) -> JoinHandle < <Self :: Future as Future >:: Output > {
320269 tokio:: spawn ( self )
321270 }
322271}
323272
324- #[ cfg( all ( test, feature = "metrics" ) ) ]
273+ #[ cfg( test) ]
325274mod test {
326275 use {
327276 super :: * ,
@@ -356,7 +305,7 @@ mod test {
356305 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
357306 b. fetch_add ( 1 , Ordering :: SeqCst ) ;
358307 } )
359- . spawn ( "" )
308+ . spawn ( )
360309 } ;
361310
362311 tokio:: time:: sleep ( Duration :: from_millis ( 200 ) ) . await ;
@@ -385,7 +334,7 @@ mod test {
385334 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
386335 b. fetch_add ( 1 , Ordering :: Relaxed ) ;
387336 } )
388- . spawn ( "" )
337+ . spawn ( )
389338 } ;
390339
391340 tokio:: time:: sleep ( Duration :: from_millis ( 200 ) ) . await ;
@@ -416,7 +365,7 @@ mod test {
416365 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
417366 b. fetch_add ( 1 , Ordering :: Relaxed ) ;
418367 } )
419- . spawn ( "" )
368+ . spawn ( )
420369 } ;
421370
422371 assert_eq ! ( handle. await . unwrap( ) , Err ( Error :: Timeout ) ) ;
@@ -441,7 +390,7 @@ mod test {
441390 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
442391 b. fetch_add ( 1 , Ordering :: Relaxed ) ;
443392 } )
444- . spawn ( "" )
393+ . spawn ( )
445394 } ;
446395
447396 assert_eq ! ( handle. await . unwrap( ) , Ok ( 42 ) ) ;
0 commit comments