Skip to content

Instantly share code, notes, and snippets.

@muraiki
Created August 26, 2015 14:57
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/f0b2b0c2a9e2aa370970 to your computer and use it in GitHub Desktop.
Save muraiki/f0b2b0c2a9e2aa370970 to your computer and use it in GitHub Desktop.
two greps on one supply
# When two greps are used on one supply, the one that matches is triggered twice.
# Run the following, then in the same directory `touch watchfile`
# Output:
# got file change: "watchfile"
# got file change: "watchfile"
# Expected output should only be a single line, not two.
# Each additional grep I add to the supply yields an additional output line.
my $paths = IO::Notification.watch_path('.')\
.grep(*.event.isa(FileChangeEvent::FileChanged))\
.unique(:as(*.path), :expires(5))\
.map(*.path);
my $watch = $paths.grep(* ~~ /watchfile/)\
.act(-> $x {
say "got file change: " ~ $x.perl;
});
my $never = $paths.grep(* ~~ /shouldneverexecute/)\
.act(-> $x {
say "should never execute: " ~ $x.perl;
});
sleep;
@muraiki
Copy link
Author

muraiki commented Aug 26, 2015

I also tried testing this without using IO::Notification, and could not reproduce the bug.

my $s = Supply.new();

my $watch = $s.grep(* ~~ /1/)\
    .act(-> $x {    
        say "got one";
    });    

my $never = $s.grep(* ~~ /shouldneverexecute/)\
    .act(-> $x {
        say "should never execute";
    }); 

$s.emit(1);
$s.emit(2);

sleep;

# Output:
#   got one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment