Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB

3 years ago
  1. package wow.doge.mygame.utils
  2. import monix.reactive.Observable
  3. import monix.reactive.OverflowStrategy
  4. import monix.execution.Cancelable
  5. import monix.execution.cancelables.SingleAssignCancelable
  6. import monix.execution.Ack
  7. object MonixDirectoryWatcher {
  8. import better.files._
  9. import io.methvin.better.files._
  10. def apply(path: os.Path) =
  11. Observable.create[String](OverflowStrategy.DropNew(50)) { sub =>
  12. import sub.scheduler
  13. val c = SingleAssignCancelable()
  14. val myDir = File(path.toString)
  15. val watcher = new RecursiveFileMonitor(myDir) {
  16. override def onCreate(file: File, count: Int) =
  17. println(s"$file got created")
  18. override def onModify(file: File, count: Int) =
  19. // println(s"$file got modified $count times")
  20. if (sub.onNext(file.name) == Ack.Stop) c.cancel()
  21. override def onDelete(file: File, count: Int) =
  22. println(s"$file got deleted")
  23. }
  24. watcher.start()(scheduler)
  25. c := Cancelable(() => watcher.stop())
  26. c
  27. }
  28. }