Skip to content

Instantly share code, notes, and snippets.

@earino
Created July 6, 2012 16: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 earino/3061200 to your computer and use it in GitHub Desktop.
Save earino/3061200 to your computer and use it in GitHub Desktop.
Using random backoff
use POE;
use POE::Component::Client::TCP;
use Proc::BackOff::Random;
my $backoff = Proc::BackOff::Random->new( {
min => 5 ,
max => 100 } );
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