Skip to content

Commit

Permalink
feat: introduce startClientFactories method
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Oct 23, 2024
1 parent d6acac1 commit 96e576a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/src/core/implementation/servient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ abstract class Servient {
/// discovering Things.
Future<scripting_api.WoT> start();

/// Synchronously starts this [Servient] and returns a [scripting_api.WoT]
/// runtime object.
///
/// In contrast to the [start] method, this method only initializes the
/// [ProtocolClientFactory]s and not the [ProtocolServer]s registered with
/// this [Servient].
/// This has the advantage that it is not necessary to return a [Future].
scripting_api.WoT startClientFactories();

/// Adds a new [clientFactory] to this [Servient].
void addClientFactory(ProtocolClientFactory clientFactory);

Expand Down Expand Up @@ -89,18 +98,23 @@ class InternalServient implements Servient {
/// The [ContentSerdes] object that is used for serializing/deserializing.
final ContentSerdes contentSerdes;

@override
WoT startClientFactories() {
for (final clientFactory in _clientFactories.values) {
clientFactory.init();
}

return WoT(this);
}

@override
Future<WoT> start() async {
final serverStatuses = _servers
.map((server) => server.start(_serverSecurityCallback))
.toList(growable: false);

for (final clientFactory in _clientFactories.values) {
clientFactory.init();
}

await Future.wait(serverStatuses);
return WoT(this);
return startClientFactories();
}

@override
Expand Down

0 comments on commit 96e576a

Please sign in to comment.