Skip to content

Instantly share code, notes, and snippets.

@muraiki
Last active September 4, 2015 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muraiki/222814d5928f648be3c1 to your computer and use it in GitHub Desktop.
Save muraiki/222814d5928f648be3c1 to your computer and use it in GitHub Desktop.
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
Copy link
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