> This page is for version 5.0 (Latest) (default).
> For other versions, use one of these documentation indexes:
> - 5.0 (Latest) (default): https://docs.nvidia.com/holoscan/sdk-user-guide/5-0-latest/llms.txt
> - ltsb-2.0: https://docs.nvidia.com/holoscan/sdk-user-guide/ltsb-2-0/llms.txt
> - 4.6: https://docs.nvidia.com/holoscan/sdk-user-guide/4-6/llms.txt
> - 4.5: https://docs.nvidia.com/holoscan/sdk-user-guide/4-5/llms.txt
> - 4.4: https://docs.nvidia.com/holoscan/sdk-user-guide/4-4/llms.txt
> - 4.3: https://docs.nvidia.com/holoscan/sdk-user-guide/4-3/llms.txt
> - Archives: https://docs.nvidia.com/holoscan/sdk-user-guide/archives/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::channel_internal::WaitSetSubscriber

> Attach one private Channel subscriber to a shared backend wait set.

Attach one private Channel subscriber to a shared backend wait set.

Implementations retain their own backend attachment, which keeps the shared wait backend and subscriber transport port alive independently of the wait-set facade. The facade therefore may be destroyed before attached subscriber wrappers; later attachment destruction still detaches safely. This transport-private interface lets Runtime multiplex inline, [Tensor](../../../classes/tensor), and Tensor-schema subscribers without exposing backend endpoint or wait-set types.

```cpp showLineNumbers={false}
#include <holoscan/channel_internal/endpoint_interfaces.hpp>
```

---

## Constructors

### WaitSetSubscriber \[#waitsetsubscriber]

#### Default

```cpp showLineNumbers={false}
HOLOSCAN_CORE_EXPORT holoscan::channel_internal::WaitSetSubscriber::WaitSetSubscriber()
```

Construct a subscriber with no wait context; one is built on the first wait.

> **Note**
>
> Defined out of line because the cached wait context is an incomplete type here, and a defaulted constructor would need its deleter instantiated for construction-time unwinding.

#### Deleted overloads

The following overloads are deleted to prevent misuse:

```cpp showLineNumbers={false}
holoscan::channel_internal::WaitSetSubscriber::WaitSetSubscriber(const WaitSetSubscriber &) = delete;
holoscan::channel_internal::WaitSetSubscriber::WaitSetSubscriber(WaitSetSubscriber &&) = delete;
```

### Destructor \[#destructor]

### \~WaitSetSubscriber

```cpp showLineNumbers={false}
virtual HOLOSCAN_CORE_EXPORT holoscan::channel_internal::WaitSetSubscriber::~WaitSetSubscriber()
```

---

## Assignment operators

### operator= \[#operator_assign]

#### Deleted overloads

The following overloads are deleted to prevent misuse:

```cpp showLineNumbers={false}
WaitSetSubscriber & holoscan::channel_internal::WaitSetSubscriber::operator=(const WaitSetSubscriber &) = delete;
WaitSetSubscriber & holoscan::channel_internal::WaitSetSubscriber::operator=(WaitSetSubscriber &&) = delete;
```

---

## Methods

### attach_wait_set \[#attachwaitset]

```cpp showLineNumbers={false}
virtual expected<std::uint64_t, Error> holoscan::channel_internal::WaitSetSubscriber::attach_wait_set(
    void *wait_set
)
```

Attach this subscriber to an opaque backend wait set.

**Returns:** Stable wait-set-local identity, or ErrorCode::kInvalidArgument for a null or repeated attachment, or another checked backend setup error.

**Parameters**

**`wait_set`** `void *`

Non-null backend-private wait-set address retained by the caller.

---

### detach_wait_set \[#detachwaitset]

```cpp showLineNumbers={false}
virtual expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::detach_wait_set() noexcept
```

Detach this subscriber from its current opaque backend wait set.

> **Note**
>
> A readiness pump or waiter must be joined before this cold lifecycle operation.

**Returns:** Success after the attachment is retired, including when none was created.

### close_local_endpoint \[#closelocalendpoint]

```cpp showLineNumbers={false}
virtual expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::close_local_endpoint() noexcept
```

Retire source-private local endpoint resources before owner destruction.

> **Note**
>
> This operation is local consumer teardown. It publishes no producer operation or EOS.

**Returns:** Success, or the allocation-free code of the first detach failure.

### has_samples \[#hassamples]

```cpp showLineNumbers={false}
virtual expected<bool, Error> holoscan::channel_internal::WaitSetSubscriber::has_samples() const
```

Query pending samples without consuming one.

> **Note**
>
> Readiness is a snapshot hint. A following receive may still report ErrorCode::kNotReady when a lossy replacement, a private control operation, or a competing consumer changed the queue in between. Implementations that own more than one transport lane report the union, so one call answers for the whole subscriber.

**Returns:** Readiness, or a checked backend query error.

### event_wake_enabled \[#eventwakeenabled]

```cpp showLineNumbers={false}
virtual bool holoscan::channel_internal::WaitSetSubscriber::event_wake_enabled() const noexcept
```

Return whether this subscriber's service admits kernel event wake.

> **Note**
>
> This function does not throw. It is a frozen creation-time fact, not a runtime state.

**Returns:** True when the service-static ChannelOptions::enable_event_wake contract is enabled for this endpoint.

### wait_set_attached \[#waitsetattached]

```cpp showLineNumbers={false}
virtual bool holoscan::channel_internal::WaitSetSubscriber::wait_set_attached() const noexcept
```

Return whether a backend wait owner currently retains this subscriber's lanes.

**Returns:** True for a Runtime pump, cached private wait context, or readiness handle.

### readiness_handle_attached \[#readinesshandleattached]

```cpp showLineNumbers={false}
virtual bool holoscan::channel_internal::WaitSetSubscriber::readiness_handle_attached() const noexcept
```

Return whether a readiness handle specifically retains this subscriber's lanes.

**Returns:** True for an external readiness handle, false for a Runtime or private wait set.

### readiness \[#readiness]

```cpp showLineNumbers={false}
virtual expected<ChannelReadinessHandle, Error> holoscan::channel_internal::WaitSetSubscriber::readiness()
```

Claim this subscriber's readiness descriptor for an external event loop.

**Returns:** A move-only readiness handle, or a checked capability or ownership error.

### claim_wait_owner \[#claimwaitowner]

```cpp showLineNumbers={false}
HOLOSCAN_CORE_EXPORT expected<WaitOwnerGuard, Error> holoscan::channel_internal::WaitSetSubscriber::claim_wait_owner() noexcept
```

Claim the subscriber's single wait-owner slot for one complete wait operation.

**Returns:** An RAII claim, or ErrorCode::kInvalidArgument when another owner is active.

### claim_readiness_owner \[#claimreadinessowner]

```cpp showLineNumbers={false}
HOLOSCAN_CORE_EXPORT expected<WaitOwnerGuard, Error> holoscan::channel_internal::WaitSetSubscriber::claim_readiness_owner() noexcept
```

Claim the owner slot and release a cached private wait context before handle creation.

**Returns:** An RAII claim, or a checked ownership or detach error.

### wait_for_readiness \[#waitforreadiness]

```cpp showLineNumbers={false}
HOLOSCAN_CORE_EXPORT expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::wait_for_readiness(
    std::chrono::steady_clock::time_point deadline,
    const std::stop_token *stop_token
) noexcept
```

Block until this subscriber may have a sample, the deadline expires, or a stop is requested.

The first call builds and caches a private wait set, attaches this subscriber's transport lanes and a cancellation trigger, and establishes the inbound connection. Later calls reuse that context and rebuild none of it. They are not unconditionally allocation-free: the wait backend records which lanes woke it in a vector that is cleared rather than shrunk and is still empty after setup, so the first later call that a lane actually satisfies grows it once. That growth is bounded by the lane count and does not recur, and the first wait after a cancellation allocates a replacement trigger. Nothing on this path allocates per call.

> **Note**
>
> The wait is event-driven with a bounded recovery poll, not purely event-driven. A publication wakes it from a kernel wait, but transport notification is best effort, so a blocked wait also re-checks readiness about once a second. An idle waiting subscriber therefore costs roughly one wakeup per second rather than nothing at all, and readiness that is reported by a lane which is not attached to the wait set – currently the catalog clock-health lane – is discovered on that fallback rather than by a wake. Treat the interval as an implementation bound rather than a contract.

> **Note**
>
> Cancellation is spelled `std::stop_token` here on purpose: a token is reusable and standard, where the transport's own wake primitive is a monotonic single-use latch. This layer owns one of those internally and fires it from a `std::stop_callback`, so a caller never has to see it or replace it after a cancellation. Naming the transport type here would breach this header's transport opacity, so the pointer runs the other way: the transport header documents the correspondence.

> **Note**
>
> This function does not throw: an allocation failure on the setup path is translated to ErrorCode::kResourceExhausted rather than crossing the `noexcept` boundary. One subscriber supports one waiting thread; calls are not internally serialized. A second concurrent waiter is rejected with ErrorCode::kInvalidArgument in every build configuration, rather than being allowed to share the first waiter's wait context. The rejected call does not disturb the wait already in flight.

> **Note**
>
> Public subscriber helpers retain one owner claim across their complete receive loop and call [wait_for_readiness_claimed](#waitforreadinessclaimed). This unclaimed entry point remains exported for existing direct callers and acquires its own claim.

**Returns:** Empty success when a sample may be available, or a checked wait error.

**Parameters**

**`deadline`** `std::chrono::steady_clock::time_point`

Steady-clock coordinate after which the wait reports a timeout.

---

**`stop_token`** `const std::stop_token *`

Optional borrowed cancellation observer; null disables cancellation.

---

### wait_for_readiness_claimed \[#waitforreadinessclaimed]

```cpp showLineNumbers={false}
HOLOSCAN_CORE_EXPORT expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::wait_for_readiness_claimed(
    std::chrono::steady_clock::time_point deadline,
    const std::stop_token *stop_token
) noexcept
```

Wait while the caller retains a successful [claim_wait_owner](#claimwaitowner) result.

**Returns:** Empty success when readiness may exist, or a checked wait error.

**Parameters**

**`deadline`** `std::chrono::steady_clock::time_point`

Steady-clock coordinate after which the wait reports a timeout.

---

**`stop_token`** `const std::stop_token *`

Optional borrowed cancellation observer.

---

### wait_context_runtime \[#waitcontextruntime]

```cpp showLineNumbers={false}
virtual void * holoscan::channel_internal::WaitSetSubscriber::wait_context_runtime() noexcept
```

Return the private transport runtime used to build this subscriber's wait context.

> **Note**
>
> The parent Channel runtime outlives every endpoint created from it, so the returned borrow stays valid for this subscriber's lifetime. This stays in `channel_internal` rather than being protected so a composite binding can delegate to the inner binding that owns the transport lanes.

**Returns:** Borrowed backend-private runtime address, or nullptr when this binding has none.

### wait_for_readiness_checked \[#waitforreadinesschecked]

```cpp showLineNumbers={false}
expected<void, Error> holoscan::channel_internal::WaitSetSubscriber::wait_for_readiness_checked(
    std::chrono::steady_clock::time_point deadline,
    const std::stop_token *stop_token
)
```

Body of [wait_for_readiness](#waitforreadiness).

Separated so the public entry point is a thin translator that can catch an allocation failure and honour its `noexcept`, rather than asserting a promise the body cannot keep. Private and non-virtual, so it adds no layout or vtable surface.

---

## Member variables

| Name            | Type                                       | Description                                                                                                                      |
| --------------- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| `wait_context_` | `std::unique_ptr< SubscriberWaitContext >` |                                                                                                                                  |
| `waiting_`      | `std::atomic_flag`                         | Claimed for the duration of one wait, so a second concurrent waiter can be rejected rather than allowed to share wait_context\_. |

---

## Inner classes

### WaitOwnerGuard

```cpp showLineNumbers={false}
class holoscan::channel_internal::WaitSetSubscriber::WaitOwnerGuard
```

Hold one exclusive wait-owner claim for a complete public wait operation.

| Name       | Type                 | Description |
| ---------- | -------------------- | ----------- |
| `waiting_` | `std::atomic_flag *` |             |