develooper Front page | perl.perl6.users | Postings from October 2018

Re: KEEP/UNDO phaser question

Thread Previous
From:
Elizabeth Mattijsen
Date:
October 28, 2018 09:21
Subject:
Re: KEEP/UNDO phaser question
Message ID:
524C9E4E-583C-4156-B202-7224C835D074@dijkmat.nl
> On 28 Oct 2018, at 01:51, Norman Gaywood <ngaywood@gmail.com> wrote:
> Just been reading  the latest of Elizabeth's wonderful blog posts on how phasers work in perl6: https://opensource.com/article/18/10/how-phasers-work-perl-6
> 
> I have question on the KEEP/UNDO example:
> {
>     KEEP $dbh.commit;
>     UNDO $dbh.rollback;
>     ...    # set up a big transaction in a database
>     True;  # indicate success
> }
> 
> Won't that "True;  # indicate success" just force the KEEP phaser to run? Shouldn't you just use the result of  whatever  is the result of "... # set up a big transaction in a database"?

That it would indeed.  The theory behind that is that if you got there, all went ok.  And that if anything went wrong in the … , you would have either returned False or thrown an exception.

You’re right, it can be a variable holding a result as well, of course.  But I also wanted to convey the fact that if the block was exited in some other way (usually with an exception), it would run the UNDO phaser.

I guess I could have been more explicit.



Liz
Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About