Skip to content

Instantly share code, notes, and snippets.

@earino
Created July 6, 2012 16:29
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 earino/3061188 to your computer and use it in GitHub Desktop.
Save earino/3061188 to your computer and use it in GitHub Desktop.
Using linear backoff
use POE;
use POE::Component::Client::TCP;
use Proc::BackOff::Linear;
my $backoff = Proc::BackOff::Linear->new( {
slope => 5,
b => 0,
x => 'count' } );
$backoff->max_timeout(60 * 5);
POE::Component::Client::TCP->new(
RemoteAddress => $config{'scanner_host'},
RemotePort => $config{'scanner_port'},
Connected => sub {
$backoff->success();
},
ServerInput => sub {
# do stuff
$backoff->success();
,
Disconnected => sub {
$kernel->delay( reconnect => $backoff->delay() );
$backoff->failure();
},
ServerError => sub {
$kernel->delay( reconnect => $backoff->delay() );
$backoff->failure();
},
}
POE::Kernel->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment