Skip to content

Instantly share code, notes, and snippets.

/tx.diff Secret

Created September 8, 2014 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/450af60525af294150cf to your computer and use it in GitHub Desktop.
Save anonymous/450af60525af294150cf to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojolicious/Plugin/DefaultHelpers.pm b/lib/Mojolicious/Plugin/D
index 00e9f5b..eae6a62 100644
--- a/lib/Mojolicious/Plugin/DefaultHelpers.pm
+++ b/lib/Mojolicious/Plugin/DefaultHelpers.pm
@@ -230,13 +230,16 @@ Check or get name of current route.
Disable automatic rendering and use L<Mojo::IOLoop/"delay"> to manage
callbacks and control the flow of events, which can help you avoid deep nested
closures and memory leaks that often result from continuation-passing style.
-Calls L<Mojolicious::Controller/"render_exception"> if an error occured in one
-of the steps, breaking the chain.
+Also keeps a reference to L<Mojolicious::Controller/"tx"> in case the
+underlying connection gets closed early and calls
+L<Mojolicious::Controller/"render_exception"> if an error occured in one of
+the steps, breaking the chain.
# Longer version
$c->render_later;
+ my $tx = $c->tx;
my $delay = Mojo::IOLoop->delay(sub {...}, sub {...});
- $delay->catch(sub { $c->render_exception(pop) })->wait;
+ $delay->catch(sub { $c->render_exception(pop) and undef $tx })->wait;
=head2 dumper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment