Skip to content

Commit

Permalink
improve inactivity_timeout helper to return the current controller ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
kraih committed Dec 7, 2015
1 parent 5b97a12 commit 2791471
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

6.36 2015-12-06
6.36 2015-12-07
- Improved Mojo::JSON performance slightly. (haarg)
- Improved inactivity_timeout helper to return the current controller object.

6.35 2015-12-04
- Removed deprecated collecting method from Mojo::UserAgent::CookieJar.
Expand Down
8 changes: 5 additions & 3 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -128,8 +128,10 @@ sub _fallbacks {
}

sub _inactivity_timeout {
return unless my $stream = Mojo::IOLoop->stream(shift->tx->connection // '');
$stream->timeout(shift);
my ($c, $timeout) = @_;
my $stream = Mojo::IOLoop->stream($c->tx->connection // '');
$stream->timeout($timeout) if $stream;
return $c;
}

sub _is_fresh {
Expand Down Expand Up @@ -345,7 +347,7 @@ Alias for L<Mojolicious::Controller/"flash">.
=head2 inactivity_timeout
$c->inactivity_timeout(3600);
$c = $c->inactivity_timeout(3600);
Use L<Mojo::IOLoop/"stream"> to find the current connection and increase
timeout if possible.
Expand Down
5 changes: 2 additions & 3 deletions t/mojo/websocket.t
Expand Up @@ -111,9 +111,8 @@ websocket '/close' => sub {
};

websocket '/timeout' => sub {
my $c = shift;
$c->inactivity_timeout(0.25);
$c->on(finish => sub { shift->stash->{finished}++ });
shift->inactivity_timeout(0.25)
->on(finish => sub { shift->stash->{finished}++ });
};

# URL for WebSocket
Expand Down

0 comments on commit 2791471

Please sign in to comment.