Last active
December 29, 2015 09:18
-
-
Save davidgrenier/7649065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FileChange = | |
| Changed of string | |
| Deleted of string | |
| Created of string | |
| Renamed of string * string | |
let watch folder = | |
async { | |
use fsw = new System.IO.FileSystemWatcher(folder, "*.fsx", EnableRaisingEvents = true) | |
let created = fsw.Created |> Event.map (fun x -> Created x.FullPath) | |
let changed = fsw.Changed |> Event.pairwise |> Event.map (fun (_, x) -> Changed x.FullPath) | |
let deleted = fsw.Deleted |> Event.map (fun x -> Deleted x.FullPath) | |
let renamed = fsw.Renamed |> Event.map (fun x -> Renamed(x.OldFullPath, x.FullPath)) | |
let merged = | |
created | |
|> Event.merge changed | |
|> Event.merge deleted | |
|> Event.merge renamed | |
while true do | |
let! change = Async.AwaitEvent merged | |
printfn "%A" change | |
} |> Async.Start | |
watch "C:\Scripts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be careful there I'm thinking you could be missing events this way.
Might be safer to subscribe directly instead and push as messages to a mailboxprocessor.