Skip to content
Browse files

Fixed non-blocking

  • Loading branch information...
1 parent 6b1e881 commit 1a24f5844a99cd5487c7a1945125023283777150 Akron committed Apr 3, 2013
Showing with 17 additions and 6 deletions.
  1. +1 −0 Changes
  2. +16 −6 lib/Mojolicious/Plugin/Piwik.pm
View
1 Changes
@@ -1,5 +1,6 @@
0.11 2013-04-03
- Improved test suite.
+ - Fixed non-blocking helper.
0.10 2013-03-04
- Delete mentioning api_test in documentation.
View
22 lib/Mojolicious/Plugin/Piwik.pm
@@ -2,6 +2,7 @@ package Mojolicious::Plugin::Piwik;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::ByteStream 'b';
use Mojo::UserAgent;
+use Mojo::IOLoop;
our $VERSION = '0.11';
@@ -256,19 +257,28 @@ SCRIPTTAG
# Non-Blocking
else {
- $ua->get(
- $url => sub {
- my ($ua, $tx) = @_;
+
+ # Create delay object
+ my $delay = Mojo::IOLoop->delay(
+ sub {
+ my $delay = shift;
+ my $tx = shift;
my $json = {};
# Return prepared response
- $json = _prepare_response($tx->res) if $tx->success;
+ my $res = $tx->success;
+ $json = _prepare_response($res) if $res;
# Release callback
$cb->($json);
- });
- Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
+ }
+ );
+
+ $ua->get($url => $delay->begin);
+
+ # Start IOLoop if not started already
+ $delay->wait unless Mojo::IOLoop->is_running;
};
});

0 comments on commit 1a24f58

Please sign in to comment.
Something went wrong with that request. Please try again.