Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Watch source files using Supplies
# disclaimer: I'm a perl6 noob :)
my $out = Supply.new;
$out.act: -> $s { say $s }; # actor model semantics; only ever execute this in 1 thread
my $watcher = IO::Notification.watch-path($*CWD.abspath)\
.grep(*.event.isa(FileChangeEvent::FileChanged))\
.unique(:as(*.path), :expires(1))\ # unique paths over last second, to prevent double-triggering from metadata events
.map(*.path.IO)\ # convert event path strings to IO::Path objects
.grep(*.extension eq 'p6')\
.tap(-> $path { $out.emit: "Source file changed: {$path.basename}" });
sleep;
@muraiki

This comment has been minimized.

Copy link
Owner Author

muraiki commented Sep 4, 2015

You can construct any number of arbitrary watchers, which will operate concurrently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.