@@ -20,9 +20,12 @@ use crate::{
2020 skywalking_proto:: v3:: SegmentObject ,
2121} ;
2222use std:: future:: Future ;
23+ use std:: pin:: Pin ;
2324use std:: sync:: Weak ;
25+ use std:: task:: { Context , Poll } ;
2426use std:: { collections:: LinkedList , sync:: Arc } ;
2527use tokio:: sync:: OnceCell ;
28+ use tokio:: task:: JoinError ;
2629use tokio:: {
2730 sync:: {
2831 mpsc:: { self } ,
@@ -58,9 +61,7 @@ pub fn create_trace_context_from_propagation(context: PropagationContext) -> Tra
5861/// Start to reporting by global tracer, quit when shutdown_signal received.
5962///
6063/// Accept a `shutdown_signal` argument as a graceful shutdown signal.
61- pub fn reporting (
62- shutdown_signal : impl Future < Output = ( ) > + Send + Sync + ' static ,
63- ) -> JoinHandle < ( ) > {
64+ pub fn reporting ( shutdown_signal : impl Future < Output = ( ) > + Send + Sync + ' static ) -> Reporting {
6465 global_tracer ( ) . reporting ( shutdown_signal)
6566}
6667
@@ -142,8 +143,10 @@ impl Tracer {
142143 pub fn reporting (
143144 & self ,
144145 shutdown_signal : impl Future < Output = ( ) > + Send + Sync + ' static ,
145- ) -> JoinHandle < ( ) > {
146- tokio:: spawn ( Self :: do_reporting ( self . clone ( ) , shutdown_signal) )
146+ ) -> Reporting {
147+ Reporting {
148+ handle : tokio:: spawn ( self . clone ( ) . do_reporting ( shutdown_signal) ) ,
149+ }
147150 }
148151
149152 async fn do_reporting ( self , shutdown_signal : impl Future < Output = ( ) > + Send + Sync + ' static ) {
@@ -216,6 +219,19 @@ impl WeakTracer {
216219 }
217220}
218221
222+ /// Created by [Tracer::reporting].
223+ pub struct Reporting {
224+ handle : JoinHandle < ( ) > ,
225+ }
226+
227+ impl Future for Reporting {
228+ type Output = Result < ( ) , JoinError > ;
229+
230+ fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
231+ Pin :: new ( & mut self . handle ) . poll ( cx)
232+ }
233+ }
234+
219235#[ cfg( test) ]
220236mod tests {
221237 use super :: * ;
0 commit comments