ocean.io.Retry

I/O wait and retry callback manager

Provides a simple means for trying a block of code and retrying it if specified conditions occur. The default condition for retrying is if any exceptions are thrown in the code block. Custom success conditions can be easily provided as a delegate to the class' constructor.

Usage example:

import ocean.io.Retry;

// Create retry object.
auto retry = new Retry;

// Code to execute / retry.
void doSomething ( )
{
    // whatever
}

// Maximum number of times to retry code block before giving up.
const max_retries = 10;

// Execute / retry code block
retry(max_retries, doSomething());

Example using a custom delegate to determine success:

import ocean.io.Retry;

// Function to determine success of executed code block
bool decide_success ( lazy void dg )
{
    try
    {
        dg();
    }
    // Only retries on io exceptions
    catch ( IOException e )
    {
        return false;
    }

    return true;
}

// Create retry object.
auto retry = new Retry(&decide_success);

// Code to execute / retry.
void doSomething ( )
{
    // whatever
}

// Maximum number of times to retry code block before giving up.
const max_retries = 10;

// Execute / retry code block
retry(max_retries, doSomething());

An extended class, WaitRetry, implements a retryer which pauses for a specified length of time before each retry.

Members

Classes

Retry
class Retry

Basic retrying class. Retries a specified block of code a specified number of times before giving up. The 'code block' is passed as a lazy bool parameter to the loop() / opCall() method.

WaitRetry
class WaitRetry

Retrying class which waits for a specified amount of time before each retry.

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).