Skip to content

Commit

Permalink
Merge pull request #187 from eclipse-thingweb/synchronous-start
Browse files Browse the repository at this point in the history
Introduce `startClientFactories` method to Servient
  • Loading branch information
JKRhb authored Oct 23, 2024
2 parents d6acac1 + a8f519f commit 738d925
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 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 @@ -90,19 +99,29 @@ class InternalServient implements Servient {
final ContentSerdes contentSerdes;

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

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

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

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

await Future.wait(serverStatuses);
}

@override
Future<WoT> start() async {
await _startServers();

return startClientFactories();
}

@override
Future<void> shutdown() async {
for (final clientFactory in _clientFactories.values) {
Expand Down

0 comments on commit 738d925

Please sign in to comment.