Last active
December 28, 2019 01:32
-
-
Save jberger/62cbf302587fabf3f33dfed239cf322c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/Promise.pm b/lib/Mojo/Promise.pm | |
index 0c66018db..db09a0033 100644 | |
--- a/lib/Mojo/Promise.pm | |
+++ b/lib/Mojo/Promise.pm | |
@@ -185,6 +185,7 @@ sub _defer { | |
my $cbs = $self->{status} eq 'resolve' ? $self->{resolve} : $self->{reject}; | |
@{$self}{qw(cycle resolve reject)} = (undef, [], []); | |
+ $self->{handled} = 1 if $self->{status} eq 'reject' && @{ $cbs || [] }; | |
$self->ioloop->next_tick(sub { $_->(@$result) for @$cbs }); | |
} | |
@@ -228,6 +229,14 @@ sub _timer { | |
return $self; | |
} | |
+sub DESTROY { | |
+ no warnings 'uninitialized'; | |
+ my $self = shift; | |
+ return if Mojo::Util::_global_destruction(); | |
+ return if $self->{status} ne 'reject' || $self->{handled}; | |
+ return $self->ioloop->reactor->emit(error => "Uncaught (in promise): @{$self->{result}}" ); | |
+} | |
+ | |
1; | |
=encoding utf8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment