Skip Menu |

This queue is for tickets about the Syntax-Keyword-Try CPAN distribution.

Report information
The Basics
Id: 133273
Status: open
Priority: 0/
Queue: Syntax-Keyword-Try

People
Owner: Nobody in particular
Requestors: TEAM [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.18
Fixed in: (no value)



Subject: finally block on cancelled async sub
Given an async sub containing a try/catch/finally block, it seems reasonable to expect the finally block to run if the async sub Future is cancelled? $ perl -e'use Future; use Future::AsyncAwait; use Syntax::Keyword::Try; my $f = (async sub { try { await Future->new } finally { warn "finally!" } })->(); $f->cancel;' TODO: free saved slot type 25
Subject: skt-test-finally-block-for-async-cancel.patch
diff --git a/t/80await+try.t b/t/80await+try.t index 3e4304d..d8756f1 100644 --- a/t/80await+try.t +++ b/t/80await+try.t @@ -106,4 +106,30 @@ BEGIN { is( scalar $fret->get, "TF", '$fret for await in try/finally' ); } +{ + my $ret = ""; + + async sub with_tryfinally + { + my $f = shift; + + try { + await $f; + $ret .= "T"; + } + finally { + $ret .= "F"; + } + + return $ret; + } + + my $f1 = Future->new; + my $fret = with_tryfinally( $f1 ); + + $fret->cancel; + + is( $ret, "F", 'finally block is called when cancelled' ); +} + done_testing;
On Fri Sep 04 13:46:54 2020, TEAM wrote: Show quoted text
> > Given an async sub containing a try/catch/finally block, it seems > reasonable to expect the finally block to run if the async sub Future > is cancelled?
(a summary of a long video call:) Hrm; yes but also no. It's tricky. Outside of Future-based code, any situation try/finally encounters will either finish successfully, or in failure. The only other minor cornercase is situations like exec() or kill -9 - in those situations it is not possible for finally to do anything about it. But once futures turn up, as well as success and failure there's also the third case of a future that suspends and just never resumes again. In effect, cancellation is sortof like that. We haven't finished, nor have we failed; we just decide not to proceed any further. I think it would be unreasonable to expect try/finally to run in this case. However, accepting that there is still a need to handle cancellation somehow, I will add a feature specifically to Future::AsyncAwait for handling that. -- Paul Evans