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