Skip to content

Commit

Permalink
Require Dart 2.18, latest lints, latest CI bits (dart-archive/async#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Oct 20, 2022
1 parent c923caa commit 874d5ae
Show file tree
Hide file tree
Showing 49 changed files with 178 additions and 144 deletions.
10 changes: 10 additions & 0 deletions pkgs/async/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set update schedule for GitHub Actions
# See https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
10 changes: 5 additions & 5 deletions pkgs/async/.github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1.0
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
with:
sdk: ${{ matrix.sdk }}
- id: install
Expand All @@ -47,10 +47,10 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [2.14.1, dev]
sdk: [2.18.0, dev]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1.0
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
with:
sdk: ${{ matrix.sdk }}
- id: install
Expand Down
3 changes: 2 additions & 1 deletion pkgs/async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## 2.10.0-dev
## 2.10.0

* Add `CancelableOperation.thenOperation` which gives more flexibility to
complete the resulting operation.
* Add `CancelableCompleter.completeOperation`.
* Require Dart 2.18

## 2.9.0

Expand Down
4 changes: 4 additions & 0 deletions pkgs/async/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Dart CI](https://github.com/dart-lang/async/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/async/actions/workflows/test-package.yml)
[![pub package](https://img.shields.io/pub/v/async.svg)](https://pub.dev/packages/async)
[![package publisher](https://img.shields.io/pub/publisher/async.svg)](https://pub.dev/packages/async/publisher)

Contains utility classes in the style of `dart:async` to work with asynchronous
computations.

Expand Down
31 changes: 27 additions & 4 deletions pkgs/async/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
# https://dart.dev/guides/language/analysis-options
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
errors:
todo: ignore
language:
#strict-casts: true
#strict-inference: true
#strict-raw-types: true

linter:
rules:
- always_declare_return_types
- avoid_dynamic_calls
- avoid_unused_constructor_parameters
- comment_references
- directives_ordering
- lines_longer_than_80_chars
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- omit_local_variable_types
- package_api_docs
- prefer_relative_imports
- prefer_single_quotes
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- unnecessary_lambdas
- use_super_parameters
7 changes: 4 additions & 3 deletions pkgs/async/lib/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// Utilities that expand on the asynchronous features of the `dart:async` library.
/// Utilities that expand on the asynchronous features of the `dart:async`
/// library.
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=r0tHiCjW2w0}
library async;
Expand All @@ -11,6 +12,7 @@ export 'src/async_cache.dart';
export 'src/async_memoizer.dart';
export 'src/byte_collector.dart';
export 'src/cancelable_operation.dart';
export 'src/chunked_stream_reader.dart';
export 'src/delegate/event_sink.dart';
export 'src/delegate/future.dart';
export 'src/delegate/sink.dart';
Expand All @@ -22,9 +24,9 @@ export 'src/future_group.dart';
export 'src/lazy_stream.dart';
export 'src/null_stream_sink.dart';
export 'src/restartable_timer.dart';
export 'src/result/result.dart';
export 'src/result/error.dart';
export 'src/result/future.dart';
export 'src/result/result.dart';
export 'src/result/value.dart';
export 'src/single_subscription_transformer.dart';
export 'src/sink_base.dart';
Expand All @@ -41,4 +43,3 @@ export 'src/stream_subscription_transformer.dart';
export 'src/stream_zip.dart';
export 'src/subscription_stream.dart';
export 'src/typed_stream_transformer.dart';
export 'src/chunked_stream_reader.dart';
9 changes: 4 additions & 5 deletions pkgs/async/lib/src/async_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:async';

import 'package:async/async.dart';
import '../async.dart';

/// Runs asynchronous functions and caches the result for a period of time.
///
Expand All @@ -21,9 +21,8 @@ import 'package:async/async.dart';
/// });
/// ```
///
/// This class's timing can be mocked using [`fake_async`][fake_async].
///
/// [fake_async]: https://pub.dev/packages/fake_async
/// This class's timing can be mocked using
/// [`fake_async`](https://pub.dev/packages/fake_async).
class AsyncCache<T> {
/// How long cached values stay fresh.
///
Expand Down Expand Up @@ -80,7 +79,7 @@ class AsyncCache<T> {
///
/// Only starts counting time after the stream has been listened to,
/// and it has completed with a `done` event.
@Deprecated("Feature will be removed")
@Deprecated('Feature will be removed')
Stream<T> fetchStream(Stream<T> Function() callback) {
if (_cachedValueFuture != null) {
throw StateError('Previously used to cache via `fetch`');
Expand Down
28 changes: 15 additions & 13 deletions pkgs/async/lib/src/cancelable_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class CancelableOperation<T> {

CancelableOperation._(this._completer);

/// Creates a [CancelableOperation] with the same result as the [result] future.
/// Creates a [CancelableOperation] with the same result as the [result]
/// future.
///
/// When this operation is canceled, [onCancel] will be called and any value
/// or error later produced by [result] will be discarded.
Expand All @@ -34,10 +35,11 @@ class CancelableOperation<T> {

/// Creates a [CancelableOperation] wrapping [subscription].
///
/// This overrides [subscription.onDone] and [subscription.onError] so that
/// the returned operation will complete when the subscription completes or
/// emits an error. When this operation is canceled or when it emits an error,
/// the subscription will be canceled (unlike
/// This overrides [StreamSubscription.onDone] and
/// [StreamSubscription.onError] so that the returned operation will complete
/// when the subscription completes or emits an error.
/// When this operation is canceled or when it emits an error, the
/// subscription will be canceled (unlike
/// `CancelableOperation.fromFuture(subscription.asFuture())`).
static CancelableOperation<void> fromSubscription(
StreamSubscription<void> subscription) {
Expand All @@ -62,24 +64,24 @@ class CancelableOperation<T> {
Iterable<CancelableOperation<T>> operations) {
operations = operations.toList();
if (operations.isEmpty) {
throw ArgumentError("May not be empty", "operations");
throw ArgumentError('May not be empty', 'operations');
}

var done = false;
// Note: if one or more of the completers have already completed,
// they're not actually cancelled by this.
Future<void> _cancelAll() {
Future<void> cancelAll() {
done = true;
return Future.wait(operations.map((operation) => operation.cancel()));
}

var completer = CancelableCompleter<T>(onCancel: _cancelAll);
var completer = CancelableCompleter<T>(onCancel: cancelAll);
for (var operation in operations) {
operation.then((value) {
if (!done) _cancelAll().whenComplete(() => completer.complete(value));
if (!done) cancelAll().whenComplete(() => completer.complete(value));
}, onError: (error, stackTrace) {
if (!done) {
_cancelAll()
cancelAll()
.whenComplete(() => completer.completeError(error, stackTrace));
}
});
Expand Down Expand Up @@ -266,7 +268,7 @@ class CancelableOperation<T> {

/// Cancels this operation.
///
/// If this operation [isComplete] or [isCanceled] this call is ignored.
/// If this operation [isCompleted] or [isCanceled] this call is ignored.
/// Returns the result of the `onCancel` callback, if one exists.
Future cancel() => _completer._cancel();

Expand Down Expand Up @@ -388,7 +390,7 @@ class CancelableCompleter<T> {
///
/// If [value] is a [Future] the [operation] will complete
/// with the result of that `Future` once it is available.
/// In that case [isComplete] will be `true` before the [operation]
/// In that case [isCompleted] will be `true` before the [operation]
/// is complete.
///
/// If the type [T] is not nullable [value] may be not be omitted or `null`.
Expand Down Expand Up @@ -426,7 +428,7 @@ class CancelableCompleter<T> {
/// canceled.
void completeOperation(CancelableOperation<T> result,
{bool propagateCancel = true}) {
if (!_mayComplete) throw StateError("Already completed");
if (!_mayComplete) throw StateError('Already completed');
_mayComplete = false;
if (isCanceled) {
if (propagateCancel) result.cancel();
Expand Down
4 changes: 2 additions & 2 deletions pkgs/async/lib/src/chunked_stream_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class ChunkedStreamReader<T> {
/// Whether a read request is currently being processed.
///
/// Is `true` while a request is in progress.
/// While a read request, like [readChunk] or [readStream], is being processed,
/// no new requests can be made.
/// While a read request, like [readChunk] or [readStream], is being
/// processed, no new requests can be made.
/// New read attempts will throw instead.
bool _reading = false;

Expand Down
4 changes: 2 additions & 2 deletions pkgs/async/lib/src/delegate/event_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DelegatingEventSink<T> implements EventSink<T> {

/// Creates a wrapper that coerces the type of [sink].
///
/// Unlike [new DelegatingEventSink], this only requires its argument to be an
/// Unlike [DelegatingEventSink.new], this only requires its argument to be an
/// instance of `EventSink`, not `EventSink<T>`. This means that calls to
/// [add] may throw a [TypeError] if the argument type doesn't match the
/// reified type of [sink].
Expand All @@ -33,7 +33,7 @@ class DelegatingEventSink<T> implements EventSink<T> {
}

@override
void addError(error, [StackTrace? stackTrace]) {
void addError(Object error, [StackTrace? stackTrace]) {
_sink.addError(error, stackTrace);
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/delegate/sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DelegatingSink<T> implements Sink<T> {

/// Creates a wrapper that coerces the type of [sink].
///
/// Unlike [new DelegatingSink], this only requires its argument to be an
/// Unlike [DelegatingSink.new], this only requires its argument to be an
/// instance of `Sink`, not `Sink<T>`. This means that calls to [add] may
/// throw a [TypeError] if the argument type doesn't match the reified type of
/// [sink].
Expand Down
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/delegate/stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'dart:async';
/// Note that this is identical to [StreamView] in `dart:async`. It's provided
/// under this name for consistency with other `Delegating*` classes.
class DelegatingStream<T> extends StreamView<T> {
DelegatingStream(Stream<T> stream) : super(stream);
DelegatingStream(super.stream);

/// Creates a wrapper which throws if [stream]'s events aren't instances of
/// `T`.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/delegate/stream_consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DelegatingStreamConsumer<T> implements StreamConsumer<T> {

/// Creates a wrapper that coerces the type of [consumer].
///
/// Unlike [new StreamConsumer], this only requires its argument to be an
/// Unlike [StreamConsumer.new], this only requires its argument to be an
/// instance of `StreamConsumer`, not `StreamConsumer<T>`. This means that
/// calls to [addStream] may throw a [TypeError] if the argument type doesn't
/// match the reified type of [consumer].
Expand Down
4 changes: 2 additions & 2 deletions pkgs/async/lib/src/delegate/stream_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DelegatingStreamSink<T> implements StreamSink<T> {

/// Creates a wrapper that coerces the type of [sink].
///
/// Unlike [new StreamSink], this only requires its argument to be an instance
/// Unlike [StreamSink.new], this only requires its argument to be an instance
/// of `StreamSink`, not `StreamSink<T>`. This means that calls to [add] may
/// throw a [TypeError] if the argument type doesn't match the reified type of
/// [sink].
Expand All @@ -36,7 +36,7 @@ class DelegatingStreamSink<T> implements StreamSink<T> {
}

@override
void addError(error, [StackTrace? stackTrace]) {
void addError(Object error, [StackTrace? stackTrace]) {
_sink.addError(error, stackTrace);
}

Expand Down
6 changes: 3 additions & 3 deletions pkgs/async/lib/src/null_stream_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:async';
///
/// The sink silently drops events until [close] is called, at which point it
/// throws [StateError]s when events are added. This is the same behavior as a
/// sink whose remote end has closed, such as when a [WebSocket] connection has
/// sink whose remote end has closed, such as when a `WebSocket` connection has
/// been closed.
///
/// This can be used when a sink is needed but no events are actually intended
Expand Down Expand Up @@ -41,8 +41,8 @@ class NullStreamSink<T> implements StreamSink<T> {

/// Creates a null sink.
///
/// If [done] is passed, it's used as the [Sink.done] future. Otherwise, a
/// completed future is used.
/// If [done] is passed, it's used as the [StreamSink.done] future. Otherwise,
/// a completed future is used.
NullStreamSink({Future? done}) : done = done ?? Future.value();

/// Creates a null sink whose [done] future emits [error].
Expand Down
4 changes: 2 additions & 2 deletions pkgs/async/lib/src/restartable_timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class RestartableTimer implements Timer {

/// Creates a new timer.
///
/// The [callback] function is invoked after the given [duration]. Unlike a
/// normal non-periodic [Timer], [callback] may be called more than once.
/// The [_callback] function is invoked after the given [_duration]. Unlike a
/// normal non-periodic [Timer], [_callback] may be called more than once.
RestartableTimer(this._duration, this._callback)
: _timer = Timer(_duration, _callback);

Expand Down
5 changes: 2 additions & 3 deletions pkgs/async/lib/src/result/capture_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import 'dart:async';

import 'result.dart';
import 'capture_sink.dart';
import 'result.dart';

/// A stream transformer that captures a stream of events into [Result]s.
///
Expand All @@ -16,6 +16,5 @@ class CaptureStreamTransformer<T> extends StreamTransformerBase<T, Result<T>> {

@override
Stream<Result<T>> bind(Stream<T> source) =>
Stream<Result<T>>.eventTransformed(
source, (sink) => CaptureSink<T>(sink));
Stream<Result<T>>.eventTransformed(source, CaptureSink<T>.new);
}
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/result/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ErrorResult implements Result<Never> {
if (errorHandler is ZoneBinaryCallback) {
errorHandler(error, stackTrace);
} else {
errorHandler(error);
(errorHandler as ZoneUnaryCallback)(error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/async/lib/src/result/release_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import 'dart:async';

import 'result.dart';
import 'release_sink.dart';
import 'result.dart';

/// A transformer that releases result events as data and error events.
class ReleaseStreamTransformer<T> extends StreamTransformerBase<Result<T>, T> {
Expand Down
Loading

0 comments on commit 874d5ae

Please sign in to comment.