folly::try_call_once

Like call_once, but using a boolean return type to signal pass/fail rather than throwing exceptions.

Synopsis

Declared in <folly/synchronization/CallOnce.h>

template<
    typename OnceFlag,
    typename F,
    typename... Args>
[[nodiscard]]
bool
try_call_once(
    OnceFlag& flag,
    F&& f,
    Args&&... args) noexcept;

Description

Returns true if any previous call to try_call_once with the same once_flag has returned true or if any previous call to call_once with the same once_flag has completed without throwing an exception or if the function passed as an argument returns true; otherwise returns false.

Note: This has no parallel in the std::once_flag interface.

Return Value

true if the flag is now set, otherwise false.

NOTE

The return value should not be discarded.

Parameters

NameDescription
flagThe once-flag guarding the call.
fThe callable to invoke at most once; must be noexcept.
argsThe arguments to forward to the callable.