watch-path
ErrorsCollection

watch-path

Synthesised documentation from type/IO/Notification

From type/IO/Notification

See Original text in context

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.

The :$scheduler named argument allows you to specify which thread scheduler is going to be responsible for the notification stream; it can be omitted if the default scheduler is used.

my $supply = IO::Notification.watch-path"/var/log/syslog" );
 
$supply.tap-> $v { say "Got "$v });
 
sleep 60;

This snippet of code sets a watch on the system log file, emitting the kind of event that has occurred or capturing an error otherwise; the created Supply is tapped, and the event printed. It does so for 60 minutes, emitting something like this:

Got /var/log/syslog: FileChanged
Got /var/log/syslog: FileChanged
Got /var/log/syslog: FileChanged
Got /var/log/syslog: FileChanged
Got /var/log/syslog: FileChanged
Got /var/log/syslog: FileChanged
Got /var/log/syslog: FileChanged
Got /var/log/syslog: FileChanged

The only kind of information this method provides is the bare fact that something has change or been renamed. You will need to actually open and read the file or directory to check the actual changes.