File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " tauri " : patch
3+ ---
4+
5+ Added ` abort ` method to ` tauri::async_runtime::JoinHandle ` .
Original file line number Diff line number Diff line change @@ -35,6 +35,17 @@ static RUNTIME: OnceCell<Runtime> = OnceCell::new();
3535#[ derive( Debug ) ]
3636pub struct JoinHandle < T > ( TokioJoinHandle < T > ) ;
3737
38+ impl < T > JoinHandle < T > {
39+ /// Abort the task associated with the handle.
40+ ///
41+ /// Awaiting a cancelled task might complete as usual if the task was
42+ /// already completed at the time it was cancelled, but most likely it
43+ /// will fail with a cancelled `JoinError`.
44+ pub fn abort ( & self ) {
45+ self . 0 . abort ( ) ;
46+ }
47+ }
48+
3849impl < T > Future for JoinHandle < T > {
3950 type Output = crate :: Result < T > ;
4051 fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
@@ -108,4 +119,17 @@ mod tests {
108119 let handle = handle ( ) ;
109120 assert_eq ! ( handle. block_on( async { 0 } ) , 0 ) ;
110121 }
122+
123+ #[ tokio:: test]
124+ async fn handle_abort ( ) {
125+ let handle = handle ( ) ;
126+ let join = handle. spawn ( async { 5 } ) ;
127+ join. abort ( ) ;
128+ if let crate :: Error :: JoinError ( raw_box) = join. await . unwrap_err ( ) {
129+ let raw_error = raw_box. downcast :: < tokio:: task:: JoinError > ( ) . unwrap ( ) ;
130+ assert ! ( raw_error. is_cancelled( ) ) ;
131+ } else {
132+ panic ! ( "Abort did not result in the expected `JoinError`" ) ;
133+ }
134+ }
111135}
You can’t perform that action at this time.
0 commit comments