From 97a20baa487e7ba68a4ca6da96861f5d4d39d3b1 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Fri, 12 Jan 2024 23:29:30 +0100 Subject: [PATCH] refactor(thing_discovery): refactor _clientForUriScheme --- lib/src/core/implementation/thing_discovery.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/src/core/implementation/thing_discovery.dart b/lib/src/core/implementation/thing_discovery.dart index 1fb88dc4..e3c5dd07 100644 --- a/lib/src/core/implementation/thing_discovery.dart +++ b/lib/src/core/implementation/thing_discovery.dart @@ -71,14 +71,15 @@ class ThingDiscovery extends Stream ProtocolClient _clientForUriScheme(Uri uri) { final uriScheme = uri.scheme; - var client = _clients[uriScheme]; + final existingClient = _clients[uriScheme]; - if (client == null) { - client = _servient.clientFor(uriScheme); - _clients[uriScheme] = client; + if (existingClient != null) { + return existingClient; } - return client; + final newClient = _servient.clientFor(uriScheme); + _clients[uriScheme] = newClient; + return newClient; } @override