Table of Contents

Method DrainAsync

Namespace
NATS.Client.Core
Assembly
NATS.Client.Core.dll

DrainAsync(CancellationToken)

Drain the subscription: stop receiving new messages while letting messages already buffered be read, keeping the connection usable.

ValueTask DrainAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Bounds the best-effort PING/PONG fence wait, which lasts at most DrainPingTimeout; the token can only shorten it, not extend it past that timeout.

Returns

ValueTask

A ValueTask that represents the asynchronous drain operation.

Remarks

Sends an unsubscribe to the server, waits for a PING/PONG round-trip so messages already in flight are delivered, then completes Msgs. Keep reading Msgs until it completes to process the buffered messages. Unlike UnsubscribeAsync(), drain does not drop messages still in the socket buffer. The connection stays open.