Skip to content

Commit 7615186

Browse files
committed
Added an example and some details. Closes #2828
1 parent fc65fbe commit 7615186

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

doc/Type/IO/Notification.pod6

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ enum FileChangeEvent (:FileChanged(1), :FileRenamed(2));
1111
=for code :skip-test<compile time error>
1212
class IO::Notification {}
1313
14-
15-
Essentially, this class exists for the C<IO::Notification.watch-path($path)>
14+
Essentially, this class exists as a placeholder for the C<IO::Notification.watch-path($path)>
1615
method, that produces a L<Supply|/type/Supply>
1716
of L<C<IO::Notification::Change>|/type/IO::Notification::Change> events for a
1817
file or directory.
@@ -31,7 +30,35 @@ C<$path> is a directory, both modifications to the directory itself (for
3130
example permission changes) and to files in the directory (including new
3231
files in the directory) are reported.
3332
34-
C<:$scheduler> allows you to specify which thread scheduler is
35-
responsible for the notification stream.
33+
The C<:$scheduler> named argument allows you to specify which thread scheduler
34+
is going to be responsible for the notification stream; it can be omitted if
35+
the default scheduler is used.
36+
37+
=begin code
38+
my $supply = IO::Notification.watch-path( "/var/log/syslog" );
39+
40+
$supply.tap( -> $v { say "Got ", $v });
41+
42+
sleep 60;
43+
=end code
44+
45+
This snippet of code sets a watch on the system log file, emitting the kind
46+
of event that has occurred or capturing an error otherwise; the created
47+
C<Supply> is tapped, and the event printed. It does so for 60 minutes,
48+
emitting something like this:
49+
50+
=for code
51+
Got /var/log/syslog: FileChanged
52+
Got /var/log/syslog: FileChanged
53+
Got /var/log/syslog: FileChanged
54+
Got /var/log/syslog: FileChanged
55+
Got /var/log/syslog: FileChanged
56+
Got /var/log/syslog: FileChanged
57+
Got /var/log/syslog: FileChanged
58+
Got /var/log/syslog: FileChanged
59+
60+
The only kind of information this method provides is the bare fact that
61+
something has change or been renamed. You will need to actually open and read
62+
the file or directory to check the actual changes.
3663
3764
=end pod

0 commit comments

Comments
 (0)