when_async 1.2.2 copy "when_async: ^1.2.2" to clipboard
when_async: ^1.2.2 copied to clipboard

Contains utility classes to work with asynchronous computations. Helps with easy consumption of such computations.

when_async #

Contains utility classes to work with asynchronous computations.

Utilities #

  • When.future for executing Futures with snapshots.
    • For futures, use execute for one time execution. This only does the asynchronous future computation once and returns the last future's result in subsequent calls. To refresh the future again, use refresh.
    • To get snapshots of the asynchronous computation's state instead, use snapshots. To get refreshed snapshots, use refreshSnapshots.

Usage #

A simple usage example:

import 'package:when_async/when_async.dart';

main() {
  final _when = When.future<int>(
    () => Future.delayed(
      const Duration(seconds: 5),
      () => 1,
    ),
  );

  _when.execute(
    onLoading: () => stdout.writeln('Loading'),
    onComplete: (it) => stdout.writeln('$it'),
    onError: (e, s) => stdout.writeln('$e\n$s'),
    onFinally: () => stdout.writeln('Finally'),
  );

  // OR

  _when.snapshots((snapshot) { 
     stdout.writeln('Snapshot: ${snapshot.state}')
  });
}

Check example.dart.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

3
likes
140
pub points
4%
popularity

Publisher

verified publishermagnificsoftware.com

Contains utility classes to work with asynchronous computations. Helps with easy consumption of such computations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

meta

More

Packages that depend on when_async