closeStream method
Future<void>
closeStream({
- required String endpoint,
- required String method,
- String? parameter,
- required UuidValue methodStreamId,
- required CloseReason reason,
Implementation
Future<void> closeStream({
required String endpoint,
required String method,
String? parameter,
required UuidValue methodStreamId,
required CloseReason reason,
}) async {
var streamKey = _buildStreamKey(
endpoint: endpoint,
method: method,
parameter: parameter,
methodStreamId: methodStreamId,
);
if (parameter == null) {
var context = _outputStreamContexts[streamKey];
if (context == null) {
return;
}
// Immediate close of the stream
_updateCloseReason(streamKey, reason);
await context.controller.onCancel?.call();
unawaited(context.subscription.cancel());
} else {
var context = _inputStreamContexts.remove(streamKey);
if (context == null) {
return;
}
if (reason == CloseReason.error) {
context.controller.addError(
const StreamClosedWithErrorException(),
);
}
return _closeControllers([context.controller]);
}
}