FileWatcher.hx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package asys;
  2. import asys.uv.UVError;
  3. import haxe.NoData;
  4. import haxe.async.*;
  5. import haxe.io.FilePath;
  6. /**
  7. File watchers can be obtained with the `asys.FileSystem.watch` method.
  8. Instances of this class will emit signals whenever any file in their watched
  9. path is modified.
  10. **/
  11. class FileWatcher {
  12. /**
  13. Emitted when a watched file is modified.
  14. **/
  15. public final changeSignal:Signal<FileWatcherEvent> = new ArraySignal();
  16. /**
  17. Emitted when `this` watcher is fully closed. No further signals will be
  18. emitted.
  19. **/
  20. public final closeSignal:Signal<NoData> = new ArraySignal();
  21. /**
  22. Emitted when an error occurs.
  23. **/
  24. public final errorSignal:Signal<UVError> = new ArraySignal();
  25. private var native:FileWatcherNative;
  26. private function new(filename:FilePath, recursive:Bool) {}
  27. /**
  28. Closes `this` watcher. This operation is asynchronous and will emit the
  29. `closeSignal` once done. If `listener` is given, it will be added to the
  30. `closeSignal`.
  31. **/
  32. public function close(?listener:Listener<NoData>):Void {
  33. if (listener != null)
  34. closeSignal.once(listener);
  35. }
  36. extern public function ref():Void;
  37. extern public function unref():Void;
  38. }