# New Ticket Created by  Jonathan Stowe 
# Please include the string:  [perl #127428]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127428 >


Hi,
I was investigating some problem I was having with my own code and came upon 
this.

It appears that "done" in a whenever block in a react does not actually exit 
the react.

  react {  whenever Supply.interval(1) -> $v { say "done"; done(); }; }

will print "done" but not exit, although it would appear that the processing of 
other whenever blocks is blocked.

If however the "done" is protect by a comparison against the value passed to 
the block then it does work as expected:

   react {  whenever Supply.interval(2) -> $v { if $v == 2 {say "done"; done(); 
} }; whenever Supply.interval(1) { say "tick"}}
   tick
   tick
   tick
   tick
   done

And then exits the react.  However if the block is protected by some other 
condition (that doesn't check the value supplied to the block,) then it doesn't 
exit the react:

   react {  whenever Supply.interval(3) -> $v { if 1 == 1 {say "done"; done(); 
} }; whenever Supply.interval(1) { say "tick"}}

It appears to execute the block immediately, terminate the other whenever and 
not exit the loop.

Interestingly also if

   react {  whenever Supply.interval(3) -> $v { if Bool.pick {say "done"; 
done(); } }; whenever Supply.interval(1) { say "tick"}}

picks True first it doesn't exit but does it at least one "tick" block is 
executed. So it would appear (can you tell that I am finding more weirdness the 
harder I look :) that if it calls "done" on the time of its first execution 
then the done doesn't work correctly. This would militate against using an 
externally controlled Promise to execute a done for example.

I'm guessing that this is tricky to test but something like:

   my $p = Promise.new; 
   my $q = start { 
                   react { whenever $p { say " done"; done; } }; 
                   True 
                 }; 
    $p.keep; 
    sleep 1; 
    say $q.status;

May help somewhat.

It can all be worked around but I am sure it's not the intended behaviour.

This is with the 

This is Rakudo version 2015.12-225-g7801920 built on MoarVM version 
2015.12-29-g8079ca5
implementing Perl 6.c.




Reply via email to