I've been looking at wrapping a file watcher in an observable to aide in processing events but I'm having some trouble figuring out how to get the behaviour I want out of it. The file watcher watches a directory into which files are placed. When a file is first placed into that directory the Created event is fired on the file watcher. However if the file is large or the network connection slow then a series of Changed events are fired as the file updates. I don't want to process the file until it has finished being written so what I really need is this timeline
|Created |Changed |Changed |Changed
________________________________________________
^Write starts ^Write finishes ^Processing Starts
I looked at a number of methods of filtering the events in Rx but I couldn't get what I need which is "fire a function once a file file has not been changed for X seconds". Throttle is no good as it will lose events in the middle. Buffer is no good as events might occur on the buffer boundary.
I had thought about using timeouts but I wasn't crazy that they threw an exception and I wanted the processing to start as files were being written and not once there were no more events at all.
There is a similar question at Reactive Extensions vs FileSystemWatcher which was never really solved.
Is there a method such that I can do this easily? I'm sure this is not an uncommon use case.