Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/src/adapter/io/io_serve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,37 @@ extension RelicAppIOServeEx on RelicApp {
/// using [HttpServer.bindSecure]. Otherwise, an HTTP server will be started
/// using [HttpServer.bind].
///
/// The maximum length of the queue for incoming connections is specified by
/// [backlog]. Defaults to 0 (system-dependent)
///
/// The [v6Only] parameter controls whether an IPv6 socket accepts only IPv6
/// connections (ignored for IPv4 addresses).
///
/// The [noOfIsolates] parameter specifies the number of isolates to spawn
/// for handling requests. When greater than 1, [shared] is automatically
/// enabled to allow multiple isolates to bind to the same port.
///
/// If not specified [address] will default to [InternetAddress.loopbackIPv4],
/// and [port] to 8080.
Future<RelicServer> serve({
final InternetAddress? address,
final int port = 8080,
final SecurityContext? securityContext,
final int backlog = 0,
final bool v6Only = false,
final bool shared = false,
final int noOfIsolates = 1,
}) {
return run(
() => IOAdapter.bind(
address ?? InternetAddress.loopbackIPv4,
port: port,
context: securityContext,
backlog: backlog,
shared: shared,
v6Only: v6Only,
shared: shared || noOfIsolates > 1,
),
noOfIsolates: noOfIsolates,
);
}
}
3 changes: 2 additions & 1 deletion lib/src/relic_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ final class _MultiIsolateRelicServer implements RelicServer {
_MultiIsolateRelicServer(
final Factory<Adapter> adapterFactory,
final int noOfIsolates,
) : _children = List.generate(
) : assert(noOfIsolates > 1),
_children = List.generate(
noOfIsolates,
(_) => _IsolatedRelicServer(adapterFactory),
);
Expand Down
2 changes: 1 addition & 1 deletion test/router/relic_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void main() {
final called = StreamController<int>();
final app = RelicApp()..inject(_Injectable(() => called.add(++count)));

await app.serve();
await app.serve(noOfIsolates: 2);

final vmService = await vmi.vmServiceConnectUri(wsUri.toString());

Expand Down
Loading