20 #ifndef RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
21 #define RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
23 #include <ripple/basics/Log.h>
53 template <
typename Ret_t,
typename... Args_t>
90 template <
typename Closure>
100 "Closure arguments don't match ClosureCounter Ret_t or Args_t");
140 return closure_(std::forward<Args_t>(args)...);
155 using namespace std::chrono_literals;
173 lock, wait, [
this] { return closureCount_ == 0; }))
175 if (
auto stream = j.
error())
176 stream << name <<
" waiting for ClosureCounter::join().";
190 template <
class Closure>
198 ret.
emplace(*
this, std::forward<Closure>(closure));
226 #endif // RIPPLE_CORE_CLOSURE_COUNTER_H_INCLUDED
Substitute(Substitute &&rhs) noexcept(std::is_nothrow_move_constructible< Closure >::value)
beast::Journal debugLog()
Returns a debug journal.
ClosureCounter & operator--()
~ClosureCounter()
Destructor verifies all in-flight closures are complete.
Substitute & operator=(Substitute const &rhs)=delete
std::condition_variable allClosuresDoneCond_
ClosureCounter & operator++()
Ret_t operator()(Args_t... args)
The role of a ClosureCounter is to assist in shutdown by letting callers wait for the completion of c...
A generic endpoint for log messages.
ClosureCounter & operator=(ClosureCounter const &)=delete
ClosureCounter & counter_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Substitute(ClosureCounter &counter, Closure &&closure)
std::remove_reference_t< Closure > closure_
void join(char const *name, std::chrono::milliseconds wait, beast::Journal j)
Returns once all counted in-flight closures are destroyed.
Substitute(Substitute const &rhs)
int count() const
Current number of Closures outstanding.
std::atomic< int > closureCount_
bool joined() const
Returns true if this has been joined.
std::optional< Substitute< Closure > > wrap(Closure &&closure)
Wrap the passed closure with a reference counter.