@@ -3,9 +3,9 @@ use crate::Command;
33use notify:: { Error , Event , RecommendedWatcher , RecursiveMode , Watcher } ;
44use std:: path:: Path ;
55use std:: result:: Result ;
6- use std:: sync:: { Arc , Mutex } ;
6+ use std:: sync:: Arc ;
77use std:: time:: Duration ;
8- use tokio:: sync:: mpsc;
8+ use tokio:: sync:: { mpsc, Mutex } ;
99use tracing:: { debug, trace} ;
1010use wax:: { Glob , Pattern } ;
1111
@@ -43,16 +43,13 @@ pub async fn update(state: SharedState, _msg: Command) {
4343///
4444/// This will compare last_seen with path, updates `last_seen` if not match,
4545/// else returns true.
46- fn should_ignore ( last_seen : Arc < Mutex < String > > , path : & str ) -> bool {
46+ async fn should_ignore ( last_seen : Arc < Mutex < String > > , path : & str ) -> bool {
4747 // HACK: Always return false for project.yml
4848 let path = path. to_string ( ) ;
4949 if path. contains ( "project.yml" ) {
5050 return false ;
5151 }
52- let mut last_seen = match last_seen. lock ( ) {
53- Ok ( x) => x,
54- Err ( _) => return true ,
55- } ;
52+ let mut last_seen = last_seen. lock ( ) . await ;
5653 if last_seen. to_string ( ) == path {
5754 return true ;
5855 } else {
@@ -135,13 +132,15 @@ fn new(state: SharedState, root: String) -> tokio::task::JoinHandle<anyhow::Resu
135132 continue ;
136133 }
137134
138- debug ! ( "[FSEVENT] {:?}" , & event) ;
135+ // debug!("[FSEVENT] {:?}", &event);
139136 // NOTE: maybe better handle in tokio::spawn?
140137 match & event. kind {
141138 notify:: EventKind :: Create ( _) => {
139+ tokio:: time:: sleep ( Duration :: new ( 1 , 0 ) ) . await ;
142140 debug ! ( "[FileCreated]: {:?}" , path) ;
143141 }
144142 notify:: EventKind :: Remove ( _) => {
143+ tokio:: time:: sleep ( Duration :: new ( 1 , 0 ) ) . await ;
145144 debug ! ( "[FileRemoved]: {:?}" , path) ;
146145 }
147146 notify:: EventKind :: Modify ( m) => {
@@ -151,19 +150,20 @@ fn new(state: SharedState, root: String) -> tokio::task::JoinHandle<anyhow::Resu
151150 if !path_string. contains ( "project.yml" ) {
152151 continue ;
153152 }
153+ tokio:: time:: sleep ( Duration :: new ( 1 , 0 ) ) . await ;
154154 debug ! ( "[XcodeGenConfigUpdate]" ) ;
155155 // HACK: Not sure why, but this is needed because xcodegen break.
156- tokio:: time:: sleep ( Duration :: new ( 1 , 0 ) ) . await ;
157156 }
158157 _ => continue ,
159158 } ,
160159 notify:: event:: ModifyKind :: Name ( _) => {
161160 // HACK: only account for new path and skip duplications
162161 if !Path :: new ( & path) . exists ( )
163- || should_ignore ( last_seen. clone ( ) , & path_string)
162+ || should_ignore ( last_seen. clone ( ) , & path_string) . await
164163 {
165164 continue ;
166165 }
166+ tokio:: time:: sleep ( Duration :: new ( 1 , 0 ) ) . await ;
167167 debug ! ( "[FileRenamed]: {:?}" , path) ;
168168 }
169169 _ => continue ,
0 commit comments