On Fri, 6 Aug 2021 13:42:22 -0500 David Nicol <davidnicol@gmail.com> wrote: > wondering how defer interacts with whatever, if anything, we've got > in Perl implementing the "promise" pattern. > > TLDR: it doesn't. Since defer blocks live on the savestack, they'll interact just fine with the async/await syntax provided by Future::AsyncAwait: use feature qw( say signatures defer ); use Future; use Future::AsyncAwait; async sub x ($f) { say "1"; defer { say "4"; } await $f; say "3"; } my $f1 = Future->new; say "0"; my $fret = x($f1); say "2"; $f1->done; say "5"; Results in all 6 messages being printed in numerical order - specifically note that 4 comes after both 2 and 3. -- Paul "LeoNerd" Evans leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/Thread Previous | Thread Next