closeAll method
Closes every remaining stream, reporting error first where it returns
one.
error is given the stream id and may return null, which is the case that
matters: a transport closing under its callers wants to tell the ones that
were IN FLIGHT why their call ended, and to stay silent for the rest. A
plain close leaves the first group's await completing with nothing.
Implementation
void closeAll({Object? Function(int streamId)? error}) {
for (final entry in _controllers.entries) {
final ctl = entry.value;
if (ctl.isClosed) continue;
final reason = error?.call(entry.key);
if (reason != null) ctl.addError(reason);
unawaited(ctl.close());
}
_controllers.clear();
}