in reply to Help with exponential backoff

Something like this?

my $counter = 1; while( 1 ) { if ( data_is_waiting() ) { my $data = read_data(); do_stuff( $data ); $counter = 1; } else { sleep( 2 * $counter ); $counter++ if $counter < 60; } }

We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re^2: Help with exponential backoff
by jdtoronto (Prior) on Oct 11, 2006 at 15:47 UTC
    Thanks jasonk, that will do it.

    I was also pondering the old method of randomly selecting a random 'sleep' between 1 and 2**n, but I don't think that is necessary.

    By the way, exponentiation operator is ** not *.

    jdtoronto