closeAllStreams method
Future<void>
closeAllStreams(
)
Implementation
Future<void> closeAllStreams() async {
var inputControllers =
_inputStreamContexts.values.map((c) => c.controller).toList();
_inputStreamContexts.clear();
var outboundStreamContexts = _outputStreamContexts.values.toList();
_outputStreamContexts.clear();
var closeSubscriptionFutures = outboundStreamContexts.map(
(c) => c.subscription.cancel().timeout(
_closeTimeout,
onTimeout: () async {
await c.controller.onCancel?.call();
return null;
// This type case is needed to avoid a runtime exception
// Filed as bug on dart-lang/sdk: https://github.com/dart-lang/sdk/issues/56846
} as Future<Null> Function()?,
),
);
await Future.wait([
...closeSubscriptionFutures,
_closeControllers(inputControllers),
]);
}