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;