Add class modifiers to dart:async.

* Pure interfaces marked `interface`. That's most public classes.
* `Stream` made `mixin class`, as a proper skeleton/base implementation.
* `Zone` classes made all `final`.

Added some `<void>` to raw `Future` types.

CoreLibraryReviewExempt: Aske is away.
Tested: No functionality change, only added restrictions.
Change-Id: I91d09fbcdba7d0dfdff3887bc7c9d54364c88b05
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289221
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
Lasse R.H. Nielsen
2023-03-20 12:12:46 +00:00
committed by Commit Queue
parent 7471994270
commit 162ff41b0e
12 changed files with 45 additions and 52 deletions
@@ -13,9 +13,9 @@
class StreamSubscription {}
class _BufferingStreamSubscription extends StreamSubscription {}
class _BufferingStreamSubscription implements StreamSubscription {}
class _BroadcastSubscription extends StreamSubscription {}
class _BroadcastSubscription implements StreamSubscription {}
abstract class Stream {
StreamSubscription foobar(void onData(event)?, {Function? onError});
@@ -3,18 +3,15 @@ import self as self;
import "dart:core" as core;
abstract class StreamSubscription extends core::Object {
synthetic constructor •() → self::StreamSubscription
}
class _BufferingStreamSubscription extends core::Object implements self::StreamSubscription {
synthetic constructor •() → self::_BufferingStreamSubscription
: super core::Object::•()
;
}
class _BufferingStreamSubscription extends self::StreamSubscription {
synthetic constructor •() → self::_BufferingStreamSubscription
: super self::StreamSubscription::•()
;
}
class _BroadcastSubscription extends self::StreamSubscription {
class _BroadcastSubscription extends core::Object implements self::StreamSubscription {
synthetic constructor •() → self::_BroadcastSubscription
: super self::StreamSubscription::•()
: super core::Object::•()
;
}
abstract class Stream extends core::Object {
+1 -1
View File
@@ -8,7 +8,7 @@ part of dart.async;
///
/// Used when an error and stack trace need to be handled as a single
/// value, for example when returned by [Zone.errorCallback].
class AsyncError implements Error {
final class AsyncError implements Error {
final Object error;
final StackTrace stackTrace;
+4 -4
View File
@@ -5,8 +5,8 @@
part of dart.async;
/// Thrown when a deferred library fails to load.
class DeferredLoadException implements Exception {
DeferredLoadException(String message) : _s = message;
String toString() => "DeferredLoadException: '$_s'";
final String _s;
final class DeferredLoadException implements Exception {
final String _message;
DeferredLoadException(String message) : _message = message;
String toString() => "DeferredLoadException: '$_message'";
}
+5 -4
View File
@@ -224,7 +224,7 @@ abstract class FutureOr<T> {
/// called. That situation should generally be avoided if possible, unless
/// it's very clearly documented.
@pragma("wasm:entry-point")
abstract class Future<T> {
abstract interface class Future<T> {
/// A `Future<Null>` completed with `null`.
///
/// Currently shared with `dart:internal`.
@@ -641,7 +641,8 @@ abstract class Future<T> {
///
/// Any error from [action], synchronous or asynchronous,
/// will stop the iteration and be reported in the returned [Future].
static Future forEach<T>(Iterable<T> elements, FutureOr action(T element)) {
static Future<void> forEach<T>(
Iterable<T> elements, FutureOr action(T element)) {
var iterator = elements.iterator;
return doWhile(() {
if (!iterator.moveNext()) return false;
@@ -691,7 +692,7 @@ abstract class Future<T> {
/// }
/// // Outputs: 'Finished with 3'
/// ```
static Future doWhile(FutureOr<bool> action()) {
static Future<void> doWhile(FutureOr<bool> action()) {
_Future<void> doneSignal = new _Future<void>();
late void Function(bool) nextIteration;
// Bind this callback explicitly so that each iteration isn't bound in the
@@ -1162,7 +1163,7 @@ class TimeoutException implements Exception {
/// }
/// }
/// ```
abstract class Completer<T> {
abstract interface class Completer<T> {
/// Creates a new completer.
///
/// The general workflow for creating a new future is to 1) create a
+7 -16
View File
@@ -133,15 +133,8 @@ typedef void _TimerCallback();
/// A broadcast stream inheriting from [Stream] must override [isBroadcast]
/// to return `true` if it wants to signal that it behaves like a broadcast
/// stream.
abstract class Stream<T> {
Stream();
/// Internal use only. We do not want to promise that Stream stays const.
///
/// If mixins become compatible with const constructors, we may use a
/// stream mixin instead of extending Stream from a const class.
/// (They now are compatible. We still consider, but it's not urgent.)
const Stream._internal();
abstract mixin class Stream<T> {
const Stream();
/// Creates an empty broadcast stream.
///
@@ -1189,7 +1182,7 @@ abstract class Stream<T> {
/// If this stream emits an error, or if the call to [action] throws,
/// the returned future completes with that error,
/// and processing stops.
Future forEach(void action(T element)) {
Future<void> forEach(void action(T element)) {
_Future future = new _Future();
StreamSubscription<T> subscription =
this.listen(null, onError: future._completeError, onDone: () {
@@ -2029,7 +2022,7 @@ abstract class Stream<T> {
/// // Do some work.
/// subscription.cancel();
/// ```
abstract class StreamSubscription<T> {
abstract interface class StreamSubscription<T> {
/// Cancels this subscription.
///
/// After this call, the subscription no longer receives events.
@@ -2163,7 +2156,7 @@ abstract class StreamSubscription<T> {
/// The [EventSink] has been designed to handle asynchronous events from
/// [Stream]s. See, for example, [Stream.eventTransformed] which uses
/// `EventSink`s to transform events.
abstract class EventSink<T> implements Sink<T> {
abstract interface class EventSink<T> implements Sink<T> {
/// Adds a data [event] to the sink.
///
/// Must not be called on a closed sink.
@@ -2183,12 +2176,10 @@ abstract class EventSink<T> implements Sink<T> {
}
/// [Stream] wrapper that only exposes the [Stream] interface.
class StreamView<T> extends Stream<T> {
base class StreamView<T> extends Stream<T> {
final Stream<T> _stream;
const StreamView(Stream<T> stream)
: _stream = stream,
super._internal();
const StreamView(Stream<T> stream) : _stream = stream;
bool get isBroadcast => _stream.isBroadcast;
+7 -5
View File
@@ -8,11 +8,12 @@ part of dart.async;
// Controller for creating and adding events to a stream.
// -------------------------------------------------------------------
/// Type of a stream controller's `onListen`, `onPause` and `onResume` callbacks.
typedef void ControllerCallback();
/// Type of a stream controller's `onListen`, `onPause` and `onResume`
/// callbacks.
typedef ControllerCallback = void Function();
/// Type of stream controller `onCancel` callbacks.
typedef FutureOr<void> ControllerCancelCallback();
typedef ControllerCancelCallback = FutureOr<void> Function();
/// A controller with the stream it controls.
///
@@ -66,7 +67,7 @@ typedef FutureOr<void> ControllerCancelCallback();
/// await streamController.close();
/// isClosed = streamController.isClosed; // true
/// ```
abstract class StreamController<T> implements StreamSink<T> {
abstract interface class StreamController<T> implements StreamSink<T> {
/// The stream that this controller is controlling.
Stream<T> get stream;
@@ -368,7 +369,8 @@ abstract class StreamController<T> implements StreamSink<T> {
/// another event is in progress may cause the second event to be delayed
/// and not be delivered synchronously, and until that event is delivered,
/// the controller will not act synchronously.
abstract class SynchronousStreamController<T> implements StreamController<T> {
abstract interface class SynchronousStreamController<T>
implements StreamController<T> {
/// Adds event to the controller's stream.
///
/// As [StreamController.add], but must not be called while an event is
+1 -1
View File
@@ -1007,7 +1007,7 @@ class _StreamIterator<T> implements StreamIterator<T> {
/// An empty broadcast stream, sending a done event as soon as possible.
class _EmptyStream<T> extends Stream<T> {
const _EmptyStream() : super._internal();
const _EmptyStream();
bool get isBroadcast => true;
StreamSubscription<T> listen(void onData(T data)?,
{Function? onError, void onDone()?, bool? cancelOnError}) {
+1 -1
View File
@@ -33,7 +33,7 @@ part of dart.async;
///
/// See also:
/// * [Stopwatch] for measuring elapsed time.
abstract class Timer {
abstract interface class Timer {
/// Creates a new timer.
///
/// The [callback] function is invoked after the given [duration].
+8 -8
View File
@@ -324,7 +324,7 @@ class _ZoneFunction<T extends Function> {
/// Handlers can either stop propagating the request (by simply not calling the
/// parent handler), or forward to the parent zone, potentially modifying the
/// arguments on the way.
abstract class ZoneSpecification {
abstract final class ZoneSpecification {
/// Creates a specification with the provided handlers.
///
/// If the [handleUncaughtError] is provided, the new zone will be a new
@@ -428,7 +428,7 @@ abstract class ZoneSpecification {
/// The implementation wants to rely on the fact that the getters cannot change
/// dynamically. We thus require users to go through the redirecting
/// [ZoneSpecification] constructor which instantiates this class.
class _ZoneSpecification implements ZoneSpecification {
base class _ZoneSpecification implements ZoneSpecification {
const _ZoneSpecification(
{this.handleUncaughtError,
this.run,
@@ -479,7 +479,7 @@ class _ZoneSpecification implements ZoneSpecification {
/// zone the action has been initiated in.
/// 2. delegate calls are more efficient, since the implementation knows how
/// to skip zones that would just delegate to their parents.
abstract class ZoneDelegate {
abstract final class ZoneDelegate {
// Invoke the [HandleUncaughtErrorHandler] of the zone with a current zone.
void handleUncaughtError(Zone zone, Object error, StackTrace stackTrace);
@@ -570,7 +570,7 @@ abstract class ZoneDelegate {
/// Similarly, zones provide [bindCallbackGuarded] (and the corresponding
/// [bindUnaryCallbackGuarded] and [bindBinaryCallbackGuarded]), when the
/// callback should be invoked through [Zone.runGuarded].
abstract class Zone {
abstract final class Zone {
// Private constructor so that it is not possible instantiate a Zone class.
Zone._();
@@ -935,7 +935,7 @@ abstract class Zone {
dynamic operator [](Object? key);
}
class _ZoneDelegate implements ZoneDelegate {
base class _ZoneDelegate implements ZoneDelegate {
final _Zone _delegationTarget;
_ZoneDelegate(this._delegationTarget);
@@ -1035,7 +1035,7 @@ class _ZoneDelegate implements ZoneDelegate {
}
/// Base class for Zone implementations.
abstract class _Zone implements Zone {
abstract base class _Zone implements Zone {
const _Zone();
// TODO(floitsch): the types of the `_ZoneFunction`s should have a type for
@@ -1087,7 +1087,7 @@ abstract class _Zone implements Zone {
}
}
class _CustomZone extends _Zone {
base class _CustomZone extends _Zone {
// The actual zone and implementation of each of these
// inheritable zone functions.
// TODO(floitsch): the types of the `_ZoneFunction`s should have a type for
@@ -1515,7 +1515,7 @@ Zone _rootFork(Zone? self, ZoneDelegate? parent, Zone zone,
return _CustomZone(zone, specification, valueMap);
}
class _RootZone extends _Zone {
base class _RootZone extends _Zone {
const _RootZone();
_ZoneFunction<RunHandler> get _run =>
+2 -1
View File
@@ -37218,7 +37218,8 @@ class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
bool get isBroadcast => true;
}
class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
class _EventStreamSubscription<T extends Event>
implements StreamSubscription<T> {
int _pauseCount = 0;
EventTarget? _target;
final String _eventType;
+2 -1
View File
@@ -219,7 +219,8 @@ class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
bool get isBroadcast => true;
}
class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
class _EventStreamSubscription<T extends Event>
implements StreamSubscription<T> {
int _pauseCount = 0;
EventTarget? _target;
final String _eventType;