@@ -36,15 +36,13 @@ pub trait Task<Ctx>: Debug + Send + Any + AsAny {
3636 /// Return `TaskType::Async` will run `self::async_run`
3737 fn get_task_type ( & self ) -> TaskType ;
3838
39- /// Sync task process
40- ///
41- /// The context is shared with all tasks
42- async fn sync_run ( self : Box < Self > , _context : & mut Ctx ) -> TaskResult < Ctx > {
39+ /// can be running in main thread
40+ async fn main_run ( self : Box < Self > , _context : & mut Ctx ) -> TaskResult < Ctx > {
4341 unreachable ! ( ) ;
4442 }
4543
46- /// Async task process
47- async fn async_run ( self : Box < Self > ) -> TaskResult < Ctx > {
44+ /// can be running in background thread
45+ async fn background_run ( self : Box < Self > ) -> TaskResult < Ctx > {
4846 unreachable ! ( ) ;
4947 }
5048}
@@ -84,15 +82,15 @@ pub async fn run_task_loop_with_event<Ctx: 'static>(
8482 let is_expected_shutdown = is_expected_shutdown. clone ( ) ;
8583 active_task_count += 1 ;
8684 tokio:: spawn ( async move {
87- let r = task. async_run ( ) . await ;
85+ let r = task. background_run ( ) . await ;
8886 if !is_expected_shutdown. load ( Ordering :: Relaxed ) {
8987 tx. send ( r) . expect ( "failed to send error message" ) ;
9088 }
9189 } ) ;
9290 }
9391 TaskType :: Sync => {
9492 // merge sync task result directly
95- match task. sync_run ( ctx) . await {
93+ match task. main_run ( ctx) . await {
9694 Ok ( r) => queue. extend ( r) ,
9795 Err ( e) => {
9896 is_expected_shutdown. store ( true , Ordering :: Relaxed ) ;
@@ -151,7 +149,7 @@ mod test {
151149 fn get_task_type ( & self ) -> TaskType {
152150 TaskType :: Sync
153151 }
154- async fn sync_run ( self : Box < Self > , context : & mut Context ) -> TaskResult < Context > {
152+ async fn main_run ( self : Box < Self > , context : & mut Context ) -> TaskResult < Context > {
155153 if context. sync_return_error {
156154 return Err ( miette ! ( "throw sync error" ) ) ;
157155 }
@@ -177,7 +175,7 @@ mod test {
177175 fn get_task_type ( & self ) -> TaskType {
178176 TaskType :: Async
179177 }
180- async fn async_run ( self : Box < Self > ) -> TaskResult < Context > {
178+ async fn background_run ( self : Box < Self > ) -> TaskResult < Context > {
181179 tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) . await ;
182180 if self . async_return_error {
183181 Err ( miette ! ( "throw async error" ) )
0 commit comments