Function write_or_flush
pub(super) async fn write_or_flush<W: AsyncWrite + Unpin>(
write: &mut W,
pending: &[u8],
needs_flush: bool,
) -> Result<Wrote>Available on crate feature
tokio only.Expand description
Writes one chunk of pending to write, or flushes when pending is
empty.
§Cancel safety
This is cancellation-safe. It performs one poll_write (or one
poll_flush) and returns. It never tracks progress across awaits, so
dropping the future before it resolves doesn’t write bytes the caller is not
told about. The caller advances its own cursor by calling consume(n) only
on a returned Wrote::Bytes. The loop uses write rather than
write_all because write_all keeps the progress cursor inside the future,
which a cancellation would lose.