Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
First pass at IO::Notification.
Provides OS-backed notification of file changes. It's a fairly raw stream; more sophisticated things based on it can likely evolve in module space for the time being.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| my enum FileChangeEvent (:FileChanged(1), :FileRenamed(2)); | ||
|
|
||
| my class IO::Notification { | ||
| my class FileWatchCancellation is repr('AsyncTask') { } | ||
|
|
||
| class Change { | ||
| has $.path; | ||
| has $.event; | ||
| } | ||
|
|
||
| method watch_path($path as Str, :$scheduler = $*SCHEDULER) { | ||
| my $s = Supply.new; | ||
| nqp::watchfile( | ||
| $scheduler.queue, | ||
| -> \path, \rename, \err { | ||
| if err { | ||
| $s.quit(err); | ||
| } | ||
| else { | ||
| my $event = rename ?? FileRenamed !! FileChanged; | ||
| $s.more(Change.new(:path(path // $path), :$event)); | ||
| } | ||
| }, | ||
| $path, FileWatchCancellation); | ||
| $s | ||
| } | ||
| } |
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