5#ifndef BITCOIN_UTIL_BTCSIGNALS_H
6#define BITCOIN_UTIL_BTCSIGNALS_H
49template <
typename Signature,
typename Combiner = null_value>
59 template <
typename Signature,
typename Combiner>
150template <
typename Signature,
typename Combiner>
159 template <
typename Callable>
200 template <typename... Args>
203 std::vector<std::shared_ptr<connection_holder>> connections;
206 connections = m_connections;
208 if constexpr (std::is_void_v<result_type>) {
209 static_assert(std::is_same_v<result_type, typename function_type::result_type>,
210 "Callback result type must be equal to the combiner result type (void).");
217 static_assert(std::is_same_v<Combiner, any_of>,
218 "only the any_of combiner is supported and hard-coded into this functor.");
219 static_assert(std::is_same_v<result_type, typename function_type::result_type>,
220 "Callback result type must be equal to the combiner result type (bool).");
235 template <
typename Callable>
241 std::erase_if(m_connections, [](
const auto& holder) {
return !holder->connected(); });
243 const auto& entry = m_connections.emplace_back(std::make_shared<connection_holder>(std::forward<Callable>(func)));
253 return std::ranges::none_of(m_connections, [](
const auto& holder) {
254 return holder->connected();
A combiner, which checks if at least one callback returned true.
std::atomic_bool m_connected
void disconnect()
If a callback is associated with this connection, prevent it from being called in the future.
std::shared_ptr< liveness > m_state
connections have shared_ptr-like copy and move semantics.
connection(std::shared_ptr< liveness > &&state)
Only a signal can create an enabled connection.
constexpr connection() noexcept=default
The default constructor creates a connection with no associated signal.
bool connected() const
Returns true if this connection was created by a signal and has not been disabled.
The default combiner, which only returns void.
scoped_connection(scoped_connection &&) noexcept=default
scoped_connection(connection rhs) noexcept
std::function< Signature > function_type
std::vector< std::shared_ptr< connection_holder > > m_connections GUARDED_BY(m_mutex)
connection connect(Callable &&func) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Combiner::result_type result_type
constexpr signal() noexcept=default
bool empty() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
btcsignals is a simple mechanism for signaling events to multiple subscribers.
const function_type m_callback
connection_holder(Callable &&callback)
#define EXCLUSIVE_LOCKS_REQUIRED(...)