move towards auto-import
This commit is contained in:
@ -35,4 +35,23 @@ public static class RxExtensions
|
||||
return src.Buffer(zeroCrossings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throttle a FileSystemObserver and eliminate all duplicates.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Curtesy of https://endjin.com/blog/2024/05/observe-file-system-changes-with-rx-dotnet
|
||||
/// </remarks>
|
||||
/// <param name="watcher">An observer created with <c>ObserveFileSystem</c></param>
|
||||
/// <param name="inactivitySeconds">Throttling window, defaults to 1 second.</param>
|
||||
/// <param name="scheduler">Scheduler to user for throttling, default is set by <c>Quiescent</c></param>
|
||||
/// <returns>A throttled observer with duplicate elimination.</returns>
|
||||
public static IObservable<IEnumerable<FileSystemEventArgs>> ThrottleAndDistinct (
|
||||
this IObservable<FileSystemEventArgs> watcher,
|
||||
int inactivitySeconds = 1,
|
||||
IScheduler? scheduler = null)
|
||||
{
|
||||
return watcher
|
||||
.Quiescent(TimeSpan.FromSeconds(inactivitySeconds), scheduler)
|
||||
.Select(changes => changes.DistinctBy(x => (x.ChangeType, x.FullPath)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user