# DescriptorDrain

- **Package:** libtmux-swift
- **Language:** Swift
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-swift/blob/e72fb5c17ab54996233b76b037c3b94a46e55685/Tests/TmuxFixture/DescriptorDrain.swift#L22
- **Bases:** [`Sendable`](https://developer.apple.com/documentation/swift/sendable), [`SendableMetatype`](https://developer.apple.com/documentation/swift/sendablemetatype)
- **Page:** https://libtmux.org/en/swift/latest/reference/descriptordrain/

Reads a descriptor until it is told to stop, and proves it has stopped before the descriptor can be closed.

Draining a pseudo-terminal keeps its client from blocking on a full buffer.
A reader that loops on `read(descriptor)` while another thread closes the
descriptor does not stop: its next call lands on whatever the process
opened next under the same number, and it consumes that file's bytes. In a
suite that spawns tmux servers concurrently, the number is soon a pipe
carrying another case's reply, so a listing arrives short or a command's
marker line never arrives, in a case that has nothing to do with this one.

``stop()`` returns only after the reader has left its loop, so the caller can
close the descriptor afterwards without a reader outliving it.

## Members

### Other members

- [`init(reading:)`](/en/swift/latest/reference/descriptordrain-init(reading-)/) (method): Starts reading `descriptor`, which the caller keeps open until ``stop()`` has returned. The descriptor is made non-blocking so the reader can notice a stop request instead of sitting in `read` through it.
- [`stop()`](/en/swift/latest/reference/descriptordrain-stop()/) (method): Stops the reader and waits until it has exited. Safe to call once.
