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

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

Thread Previous | Thread Next
From:
David Nicol
Date:
August 6, 2021 18:43
Subject:
Re: Review of `defer` (was: FINALLY - ready for comments/review)
Message ID:
CAFwScO9kcDw2Npzo1zHdTPYFqbRy=KAcYNQ0SvknHCF4zRf9og@mail.gmail.com
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,
https://github.com/domenic/promises-unwrapping/blob/master/docs/states-and-fates.md
) 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

          ALL_THE_NON_DEFERRED_CODE->then( THE_DEFERRED_CODE )

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
<https://metacpan.org/author/YANICK>'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

dln

On Wed, Jul 28, 2021 at 2:13 PM Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
wrote:

>
> > 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


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