Unverified Commit d2f9c6c7 authored by 嘟囔's avatar 嘟囔 Committed by GitHub

feat: migrate base/dds.dart to null-safety (#88015)

parent 4ef8088c
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:dds/dds.dart' as dds;
......@@ -24,10 +22,10 @@ Future<dds.DartDevelopmentService> Function(
/// Helper class to launch a [dds.DartDevelopmentService]. Allows for us to
/// mock out this functionality for testing purposes.
class DartDevelopmentService {
dds.DartDevelopmentService _ddsInstance;
dds.DartDevelopmentService? _ddsInstance;
Uri get uri => _ddsInstance?.uri ?? _existingDdsUri;
Uri _existingDdsUri;
Uri? get uri => _ddsInstance?.uri ?? _existingDdsUri;
Uri? _existingDdsUri;
Future<void> get done => _completer.future;
final Completer<void> _completer = Completer<void>();
......@@ -37,7 +35,7 @@ class DartDevelopmentService {
int hostPort,
bool ipv6,
bool disableServiceAuthCodes, {
@required Logger logger,
required Logger logger,
}) async {
final Uri ddsUri = Uri(
scheme: 'http',
......@@ -45,7 +43,7 @@ class DartDevelopmentService {
io.InternetAddress.loopbackIPv6 :
io.InternetAddress.loopbackIPv4
).host,
port: hostPort ?? 0,
port: hostPort,
);
logger.printTrace(
'Launching a Dart Developer Service (DDS) instance at $ddsUri, '
......@@ -58,12 +56,12 @@ class DartDevelopmentService {
enableAuthCodes: !disableServiceAuthCodes,
ipv6: ipv6,
);
unawaited(_ddsInstance.done.whenComplete(() {
unawaited(_ddsInstance?.done.whenComplete(() {
if (!_completer.isCompleted) {
_completer.complete();
}
}));
logger.printTrace('DDS is listening at ${_ddsInstance.uri}.');
logger.printTrace('DDS is listening at ${_ddsInstance?.uri}.');
} on dds.DartDevelopmentServiceException catch (e) {
logger.printTrace('Warning: Failed to start DDS: ${e.message}');
if (e.errorCode == dds.DartDevelopmentServiceException.existingDdsInstanceError) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment