template <typename T>
nxt::detail::signal class

The consumer end of a typed event channel.

Single-slot semantics:

  • push() with no waiter drops the value.
  • next() while one is already pending overwrites the slot and delivers nullopt to the previous waiter.
  • next(stop_token) also unregisters and returns nullopt when cancellation is requested.

Lifetime rules:

  • Destroying the signal closes the receiver side: the current pending waiter (if any) wakes with nullopt; subsequent pushes throw disconnected.
  • When the last publisher is destroyed, the sender side closes: next() wakes with nullopt.

Constructors, destructors, conversion operators

signal()
signal(const signal&) deleted
signal(signal&& other) defaulted noexcept
~signal()

Public functions

void close() noexcept
Close the receiver side. Idempotent.
auto closed() const →  bool noexcept
True once the receiver side has been closed.
auto next() const →  detail::next_awaiter<T>
auto next(std::stop_token stop) const →  detail::next_awaiter<T>
auto operator=(const signal&) →  signal& deleted
auto operator=(signal&& other) →  signal& noexcept
auto publisher() const →  detail::publisher<T>
Create a new write-endpoint. Cheap; copies share refcount.
auto publisher(T value) const →  detail::bound_publisher<T>
Create a write-endpoint that always pushes the same value.

Function documentation

template <typename T>
detail::next_awaiter<T> nxt::detail::signal::next() const

Await the next value. Returns nullopt once the signal has been closed (receiver or last publisher gone), or when the slot is pre-empted by a subsequent next().

template <typename T>
detail::next_awaiter<T> nxt::detail::signal::next(std::stop_token stop) const

Await the next value, or nullopt if the signal is closed, pre-empted, or stop is requested.