develooper Front page | perl.perl5.porters | Postings from August 2021

Re: Review of `defer` (was: FINALLY - ready for comments/review)

Thread Previous | Thread Next
David Nicol
August 6, 2021 18:43
Re: Review of `defer` (was: FINALLY - ready for comments/review)
Message ID:
wondering how defer interacts with whatever, if anything, we've got in Perl
implementing the "promise" pattern.

TLDR: it doesn't.

Re-reviewing promises with their "then" methods (for instance,
) indicates that they are entirely orthogonal, except that it might be
possible to implement defer with promises somehow, if promises was your
main flow control mechanism.

something like rewriting blocks with defer in them, to


But as defer is concerned with ordering of control within a block, it
wouldn't have side effects that would in any way hop from promise to
promise, given a promise library such as Yanick Champoux
<>'s Promises, which uses something
called "deferred" to postpone an action to the next time around the event
loop, instead of immediately. Again, the defer we are discussing here is
not concerned with asynchronous event loops.  One might use defer to
reorganize code within a callback, but that's it.

Thank you for your patience


On Wed, Jul 28, 2021 at 2:13 PM Paul "LeoNerd" Evans <>

> > b. are there any effective differences between "defer" and
> > Try::Tiny's "finally"?
> defer happens at the exit of its own containing block.
> finally of try/finally acts as if there was a containing block around
> the try/finally statement.
>   {
>     defer { say "Later"; }
>     say "First";
>   }
> equiv to
>   try { say "First"; }
>   finally { say "Later"; }

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About