This version brings a new Observable interface that exposes a “stream” (or channel) of EventAtPaths that can be composed. Using this interface, you no longer need to register callbacks - you simply register paths and get notifications for events on them either by subscribing to the Observable or by composing.
For more information on how to use Observables (especially how they compose in awesome ways), checkout the Rx homepage
importcom.beachape.filemanagement.RxMonitorimportjava.io.{FileWriter,BufferedWriter}importjava.nio.file.Pathsimportjava.nio.file.StandardWatchEventKinds._valmonitor=RxMonitor()valobservable=monitor.observablevalsubscription=observable.subscribe(onNext={p=>println(s"Something was modified in a file mufufu: $p")},onError={t=>println(t)},onCompleted={()=>println("Monitor has been shut down")})valdesktopFile=Pathsget"/Users/lloyd/Desktop/test"monitor.registerPath(ENTRY_MODIFY,desktopFile)Thread.sleep(100)//modify a monitored filevalwriter=newBufferedWriter(newFileWriter(desktopFile.toFile))writer.write("Theres text in here wee!!")writer.close// #=> Something was modified in a file mufufu: /Users/lloyd/Desktop/test// stop monitoringmonitor.stop()// #=> Monitor has been shut down