class IO::Notification

Asynchronous notification for file and directory changes

enum FileChangeEvent (:FileChanged(1), :FileRenamed(2));
class IO::Notification  {
    class Change {
        has $.path;
        has $.event;
    }
    ...
}

IO::Notification.watch-path($path) produces a Supply of IO::Notification::Change events for a file or directory.

Here is a small example that prints the first ten FileChanged-notifications for the current working directory:

my $finish = Promise.new;
my $count = 0;
IO::Notification.watch-path($*CWD).act-> $change {
    $count++ if $change.event ~~ FileChanged;
    say "($count$change.path()$change.event()";
    $finish.keep if $count >= 10;
});
await $finish;

The type of the change is very much dependent both on the platform and on specific system calls that were used initiate the change. At this point in time you should not rely on the type of change in general, and test your particular situation.

Methods

method watch-path

method watch-path(IO::Notification: Str() $path:$scheduler = $*SCHEDULER)

Returns a Supply that emits IO::Notification::Change objects.

If $path is a file, only modifications of that file are reported. If $path is a directory, both modifications to the directory itself (for example permission changes) and to files in the directory (including new files in the directory) are reported.

:$scheduler allows you to specify which thread scheduler is responsible for the notification stream.

Type Graph

Type relations for IO::Notification
perl6-type-graph IO::Notification IO::Notification Any Any IO::Notification->Any Mu Mu Any->Mu

Stand-alone image: vector