Skip to content

Commit

Permalink
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
jnthn committed Apr 21, 2014
1 parent c4efc57 commit a38725d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/core/IO/Notification.pm
@@ -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
}
}
1 change: 1 addition & 0 deletions tools/build/Makefile-Moar.in
Expand Up @@ -169,6 +169,7 @@ M_CORE_SOURCES = \
src/core/IO/Socket.pm \
src/core/IO/Socket/INET.pm \
src/core/IO/Socket/Async.pm \
src/core/IO/Notification.pm \
src/core/OS.pm \
src/core/core_epilogue.pm \

Expand Down

0 comments on commit a38725d

Please sign in to comment.