File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -24,15 +24,11 @@ pub async fn serial_connect(
2424
2525 let ( mut reader, mut writer) = tokio:: io:: split ( port) ;
2626
27+ let ahc = app_handle. clone ( ) ;
2728 let ( send, mut recv) = channel ( 5 ) ;
2829 * state. conn . lock ( ) . await = Some ( Box :: new ( send) ) ;
29- tauri:: async_runtime:: spawn ( async move {
30- while let Some ( data) = recv. next ( ) . await {
31- let _res = writer. write ( & data) . await ;
32- }
33- } ) ;
3430
35- tauri:: async_runtime:: spawn ( async move {
31+ let read_process = tauri:: async_runtime:: spawn ( async move {
3632 use tauri:: Manager ;
3733 use tauri:: Emitter ;
3834
@@ -51,6 +47,18 @@ pub async fn serial_connect(
5147 app_handle. emit ( "connection_disconnected" , ( ) ) ;
5248 } ) ;
5349
50+ tauri:: async_runtime:: spawn ( async move {
51+ use tauri:: Manager ;
52+
53+ while let Some ( data) = recv. next ( ) . await {
54+ let _res = writer. write ( & data) . await ;
55+ }
56+
57+ let state = ahc. state :: < super :: commands:: ActiveConnection > ( ) ;
58+ read_process. abort ( ) ;
59+ * state. conn . lock ( ) . await = None ;
60+ } ) ;
61+
5462 Ok ( true )
5563 }
5664 Err ( e) => {
You can’t perform that action at this time.
0 commit comments