async 2.3.0

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

  • The AsyncCache class allows expensive asynchronous computations values to be cached for a period of time.

  • The AsyncMemoizer class makes it easy to only run an asynchronous operation once on demand.

  • The CancelableOperation class defines an operation that can be canceled by its consumer. The producer can then listen for this cancellation and stop producing the future when it's received. It can be created using a CancelableCompleter.

  • The delegating wrapper classes allow users to easily add functionality on top of existing instances of core types from dart:async. These include DelegatingFuture, DelegatingStream, DelegatingStreamSubscription, DelegatingStreamConsumer, DelegatingSink, DelegatingEventSink, and DelegatingStreamSink.

    The delegating classes all have .typed() constructors which allow users to cast the generic type parameters in a way that's safe for strong mode. For example, if future is a Future<dynamic> and you know it actually contains an int, you can write DelegatingFuture.typed<int>(future).

  • The FutureGroup class makes it easy to wait until a group of features that may change over time completes.

  • The LazyStream class allows a stream to be initialized lazily when .listen() is first called.

  • The NullStreamSink class is an implementation of StreamSink that discards all events.

  • The RestartableTimer class extends Timer with a reset() method.

  • The Result class that can hold either a value or an error. It provides various utilities for converting to and from Futures and Streams.

  • The StreamGroup class merges a collection of streams into a single output stream.

  • The StreamQueue class allows a stream to be consumed event-by-event rather than being pushed whichever events as soon as they arrive.

  • The StreamSplitter class allows a stream to be duplicated into multiple identical streams.

  • The StreamZip class combines multiple streams into a single stream of lists of events.

  • This package contains a number of StreamTransformers. SingleSubscriptionTransformer converts a broadcast stream to a single-subscription stream, and typedStreamTransformer casts the type of a Stream. It also defines a transformer type for StreamSinks, StreamSinkTransformer.

  • The SubscriptionStream class wraps a StreamSubscription so it can be re-used as a Stream.

2.3.0 #

  • Implement RestartableTimer.tick.

2.2.0 #

  • Add then to CancelableOperation.

2.1.0 #

  • Fix CancelableOperation.valueOrCancellation's type signature
  • Add isCanceled and isCompleted to CancelableOperation.

2.0.8 #

  • Set max SDK version to <3.0.0.
  • Deprecate DelegatingFuture.typed, it is not necessary in Dart 2.

2.0.7 #

  • Fix Dart 2 runtime errors.
  • Stop using deprecated constants from the SDK.

2.0.6 #

  • Add further support for Dart 2.0 library changes to Stream.

2.0.5 #

2.0.4 #

  • Add support for Dart 2.0 library changes to Stream and StreamTransformer. Changed classes that implement StreamTransformer to extend StreamTransformerBase, and changed signatures of firstWhere, lastWhere, and singleWhere on classes extending Stream. See also issue 31847.

2.0.3 #

  • Fix a bug in StreamQueue.startTransaction() and related methods when rejecting a transaction that isn't the oldest request in the queue.

2.0.2 #

  • Add support for Dart 2.0 library changes to class Timer.

2.0.1 #

  • Fix a fuzzy arrow type warning.

2.0.0 #

  • Remove deprecated public result.dart and stream_zip.dart libraries and deprecated classes ReleaseStreamTransformer and CaptureStreamTransformer.

  • Add captureAll and flattenList static methods to Result.

  • Change ErrorResult to not be generic and always be a Result<Null>. That makes an error independent of the type of result it occurs instead of.

1.13.3 #

  • Make TypeSafeStream extend Stream instead of implementing it. This ensures that new methods on Stream are automatically picked up, they will go through the listen method which type-checks every event.

1.13.2 #

  • Fix a type-warning.

1.13.1 #

  • Use FutureOr for various APIs that had previously used dynamic.

1.13.0 #

  • Add collectBytes and collectBytesCancelable functions which collects list-of-byte events into a single byte list.

  • Fix a bug where rejecting a StreamQueueTransaction would throw a StateError if had been called on one of its child queues.

  • StreamQueue.withTransaction() now properly returns whether or not the transaction was committed.

1.12.0 #

  • Add an AsyncCache class that caches asynchronous operations for a period of time.

  • Add StreamQueue.peek and StreamQueue.lookAheead. These allow users to look at events without consuming them.

  • Add StreamQueue.startTransaction() and StreamQueue.withTransaction(). These allow users to conditionally consume events based on their values.

  • Add StreamQueue.cancelable(), which allows users to easily make a CancelableOperation that can be canceled without affecting the queue.

  • Add StreamQueue.eventsDispatched which counts the number of events that have been dispatched by a given queue.

  • Add a subscriptionTransformer() function to create StreamTransformers that modify the behavior of subscriptions to a stream.

1.11.3 #

  • Fix strong-mode warning against the signature of Future.then

1.11.1 #

  • Fix new strong-mode warnings introduced in Dart 1.17.0.

1.11.0 #

  • Add a typedStreamTransformer() function. This wraps an untyped StreamTransformer with the correct type parameters, and asserts the types of events as they're emitted from the transformed stream.

  • Add a StreamSinkTransformer.typed() static method. This wraps an untyped StreamSinkTransformer with the correct type parameters, and asserts the types of arguments passed in to the resulting sink.

1.10.0 #

  • Add DelegatingFuture.typed(), DelegatingStreamSubscription.typed(), DelegatingStreamConsumer.typed(), DelegatingSink.typed(), DelegatingEventSink.typed(), and DelegatingStreamSink.typed() static methods. These wrap untyped instances of these classes with the correct type parameter, and assert the types of values as they're accessed.

  • Add a DelegatingStream class. This is behaviorally identical to StreamView from dart:async, but it follows this package's naming conventions and provides a DelegatingStream.typed() static method.

  • Fix all strong mode warnings and add generic method annotations.

  • new StreamQueue(), new SubscriptionStream(), new DelegatingStreamSubscription(), new DelegatingStreamConsumer(), new DelegatingSink(), new DelegatingEventSink(), and new DelegatingStreamSink() now take arguments with generic type arguments (for example Stream<T>) rather than without (for example Stream<dynamic>). Passing a type that wasn't is-compatible with the fully-specified generic would already throw an error under some circumstances, so this is not considered a breaking change.

  • ErrorResult now takes a type parameter.

  • Result.asError now returns a Result<T>.

1.9.0 #

  • Deprecate top-level libraries other than package:async/async.dart, which exports these libraries' interfaces.

  • Add Result.captureStreamTransformer, Result.releaseStreamTransformer, Result.captureSinkTransformer, and Result.releaseSinkTransformer.

  • Deprecate CaptureStreamTransformer, ReleaseStreamTransformer, CaptureSink, and ReleaseSink. Result.captureStreamTransformer, Result.releaseStreamTransformer, Result.captureSinkTransformer, and Result.releaseSinkTransformer should be used instead.

1.8.0 #

  • Added StreamSinkCompleter, for creating a StreamSink now and providing its destination later as another sink.

  • Added StreamCompleter.setError, a shortcut for emitting a single error event on the resulting stream.

  • Added NullStreamSink, an implementation of StreamSink that discards all events.

1.7.0 #

  • Added SingleSubscriptionTransformer, a StreamTransformer that converts a broadcast stream into a single-subscription stream.

1.6.0 #

  • Added CancelableOperation.valueOrCancellation(), which allows users to be notified when an operation is canceled elsewhere.

  • Added StreamSinkTransformer which transforms events before they're passed to a StreamSink, similarly to how StreamTransformer transforms events after they're emitted by a stream.

1.5.0 #

  • Added LazyStream, which forwards to the return value of a callback that's only called when the stream is listened to.

1.4.0 #

  • Added AsyncMemoizer.future, which allows the result to be accessed before runOnce() is called.

  • Added CancelableOperation, an asynchronous operation that can be canceled. It can be created using a CancelableCompleter.

  • Added RestartableTimer, a non-periodic timer that can be reset over and over.

1.3.0 #

  • Added StreamCompleter class for creating a stream now and providing its events later as another stream.

  • Added StreamQueue class which allows requesting events from a stream before they are avilable. It is like a StreamIterator that can queue requests.

  • Added SubscriptionStream which creates a single-subscription stream from an existing stream subscription.

  • Added a ResultFuture class for synchronously accessing the result of a wrapped future.

  • Added FutureGroup.onIdle and FutureGroup.isIdle, which provide visibility into whether a group is actively waiting on any futures.

  • Add an AsyncMemoizer class for running an asynchronous block of code exactly once.

  • Added delegating wrapper classes for a number of core async types: DelegatingFuture, DelegatingStreamConsumer, DelegatingStreamController, DelegatingSink, DelegatingEventSink, DelegatingStreamSink, and DelegatingStreamSubscription. These are all simple wrappers that forward all calls to the wrapped objects. They can be used to expose only the desired interface for subclasses, or extended to add extra functionality.

1.2.0 #

  • Added a FutureGroup class for waiting for a group of futures, potentially of unknown size, to complete.

  • Added a StreamGroup class for merging the events of a group of streams, potentially of unknown size.

  • Added a StreamSplitter class for splitting a stream into multiple new streams.

1.1.1 #

  • Updated SDK version constraint to at least 1.9.0.

1.1.0 #

  • ChangeLog starts here.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  async: ^2.3.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:async/async.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Sep 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:async/async.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and async.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
collection ^1.5.0 1.14.12
Dev dependencies
fake_async ^1.0.0
pedantic ^1.0.0
stack_trace ^1.0.0
test ^1.0.0