Last active
August 29, 2015 14:26
-
-
Save Roeya/9827d3624d8af09ed42f to your computer and use it in GitHub Desktop.
This file contains 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
# This is a recurring timer I use, the | |
# the timer should fire till a certain condition | |
# is fulfilled | |
# Caveats - I get Mojo::Reactor::Poll: Timer failed: Missing or empty input | |
# from time to time | |
my ($i, $done, $id) = (0, 0, undef); | |
$id = Mojo::IOLoop->recurring(0.2 => sub { | |
return if ($done); | |
app->log->debug("waiting for $json - $i time"); | |
my $temp; | |
eval { | |
$temp = check_json_result($base_path, $json); | |
}; | |
if ($@) { | |
app->log->error("something is wrong here $@"); | |
$temp = {status => 0, error => $@}; | |
} | |
if ($temp || $i++ > $max_retries) { | |
if ($temp) { | |
app->log->debug("found $json"); | |
$hash = $temp; | |
} | |
$done = 1; | |
$c->render(json => $hash, status => 200); | |
} | |
if ($id && $done) { | |
Mojo::IOLoop->remove($id); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment