You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69Lines changed: 69 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,6 +67,75 @@ let changedFile = FolderContentMonitor(url: folderUrl)
67
67
})
68
68
```
69
69
70
+
## A Note on Latency
71
+
72
+
A latency of 0.0 (default value) can produce too much noise. Experiment with slightly higher values so the system can coalesce events when appropriate.
73
+
74
+
When you run the example app to see which kinds of events are fired, make sure to use TextEdit to create and modify a file so you see what kinds of events are bound to happen. Here's an annotated log:
You see that overwriting a file _atomically_ will fire a lot of events when you use a modern document-based macOS app like TextEdit. The authors interpretation of these events is: "get rid of the original file, move in temp file with changes, copy temp file to original file's path, then get rid of the temp file". It could mean the original file is renamed to the temporary looking name just as well as far as I know. (Which, apparently, isn't much.)
94
+
95
+
Now see the log for the same actions with a latency of 1 second:
So maybe a latency of slightly above >0.0 can help get rid of noise. Makes even more sense when you coalesce the `RxSwift.Observable` events in the end.
113
+
114
+
Note that other editors like TextMate 2 don't write to files with the same mechanism and only generate a single event, similar to what you'd expect from file changes originating in the shell:
Look at the repository's issues -- there's still a lot of room for improvement. This boils down to applying _interpretation_ and _heuristics_. In other words, it might break or be utterly wrong.
124
+
125
+
At the moment, each and every FSEvent is forwarded to the callback (or observer).
That means the library could try to make sense of event pairs and reduce them to single events for the client. Instead of forwarding an event of the form "`texteditfile.txt.sb-56afa5c6-SOiDRl` was renamed" which, in client's terms, will be interpreted as "the file was moved in there", the library could fire a single "edited" event.
135
+
136
+
Also noteworthy: the `removed` event will not be fired when trashing a file from Finder even though it was fired when TextEdit saved file changes and got rid of the intermediate result file. Some `renamed` events thus really are `removed` events and you need to check the file at the URL for existence after the event comes in. With a certain latency, or else you may pick up the about-to-be-trashed file _before_ its being moved is completed.
0 commit comments