stop method
Cancels the input subscription and closes the result stream. Idempotent.
Implementation
Future<void> stop() async {
if (_stopped) return;
_stopped = true;
final sub = _sub;
_sub = null;
await sub?.cancel();
if (!_out.isClosed) await _out.close();
}