LLVM 19.0.0git
Public Types | Public Member Functions | List of all members
llvm::ExponentialBackoff Class Reference

A class to help implement exponential backoff. More...

#include "llvm/Support/ExponentialBackoff.h"

Public Types

using duration = std::chrono::steady_clock::duration
 
using time_point = std::chrono::steady_clock::time_point
 

Public Member Functions

 ExponentialBackoff (duration Timeout, duration MinWait=std::chrono::milliseconds(10), duration MaxWait=std::chrono::milliseconds(500))
 
bool waitForNextAttempt ()
 Blocks while waiting for the next attempt.
 

Detailed Description

A class to help implement exponential backoff.

Example usage:

ExponentialBackoff Backoff(10s);
do {
if (tryToDoSomething())
return ItWorked;
} while (Backoff.waitForNextAttempt());
return Timeout;
A class to help implement exponential backoff.

Definition at line 33 of file ExponentialBackoff.h.

Member Typedef Documentation

◆ duration

using llvm::ExponentialBackoff::duration = std::chrono::steady_clock::duration

Definition at line 35 of file ExponentialBackoff.h.

◆ time_point

using llvm::ExponentialBackoff::time_point = std::chrono::steady_clock::time_point

Definition at line 36 of file ExponentialBackoff.h.

Constructor & Destructor Documentation

◆ ExponentialBackoff()

llvm::ExponentialBackoff::ExponentialBackoff ( duration  Timeout,
duration  MinWait = std::chrono::milliseconds(10),
duration  MaxWait = std::chrono::milliseconds(500) 
)
inline
Parameters
Timeoutthe maximum wall time this should run for starting when this object is constructed.
MinWaitthe minimum amount of time waitForNextAttempt will sleep for.
MaxWaitthe maximum amount of time waitForNextAttempt will sleep for.

Definition at line 44 of file ExponentialBackoff.h.

Member Function Documentation

◆ waitForNextAttempt()

bool ExponentialBackoff::waitForNextAttempt ( )

Blocks while waiting for the next attempt.

Returns
true if you should try again, false if the timeout has been reached.

Definition at line 14 of file ExponentialBackoff.cpp.

Referenced by llvm::LockFileManager::waitForUnlock().


The documentation for this class was generated from the following files: