Flutter Dev

Flutter Dev

1629625496

When_Async | Utility Classes to Work with Asynchronous 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 same 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.

 

Use this package as a library

Depend on it

Run this command:

With Dart:

 $ dart pub add when_async

With Flutter:

 $ flutter pub add when_async

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):


dependencies:
  when_async: ^1.2.1

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

Import it

Now in your Dart code, you can use:

import 'package:when_async/when_async.dart';

example/when_async_example.dart

import 'dart:io';

import 'package:when_async/when_async.dart';

class FakeError extends Error {}

Future<void> example1() {
  stdout.writeln('Example 1');

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

  final _whenError = When.future<int>(
    () => Future.delayed(
      const Duration(seconds: 5),
      () => throw FakeError(),
    ),
  );

  const _listener1 = '(execute)';

  final task1 = _when.execute(
    onLoading: () => stdout.writeln('$_listener1: Loading'),
    onComplete: (it) => stdout.writeln('$_listener1: Data: $it'),
    onError: (e, s) => stdout.writeln('$_listener1: $e'),
    onFinally: () => stdout.writeln('$_listener1: Finally'),
  );

  const _listener2 = '(executeWithError)';

  final task2 = _whenError.execute(
    onLoading: () => stdout.writeln('$_listener2: Loading'),
    onComplete: (it) => stdout.writeln('$_listener2: Data: $it'),
    onError: (e, s) => stdout.writeln('$_listener2: Error: $e'),
    onFinally: () => stdout.writeln('$_listener2: Finally'),
  );

  return Future.wait([task1, task2]);
}

Future<void> example2() {
  stdout.writeln('Example 2');

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

  final _whenError = When.future<int>(
    () => Future.delayed(
      const Duration(seconds: 5),
      () => throw FakeError(),
    ),
  );

  const _listener1 = '(snapshot)';

  final task1 = _when.snapshots(
    (snapshot) => stdout.writeln('$_listener1: ${snapshot.state}'),
    () => stdout.writeln('$_listener1: Finally'),
  );

  const _listener2 = '(snapshotWithError)';

  final task2 = _whenError.snapshots(
    (snapshot) => stdout.writeln('$_listener2: ${snapshot.state}'),
    () => stdout.writeln('$_listener2: Finally'),
  );

  return Future.wait([task1, task2]);
}

Future<void> main() async {
  await example1();
  await example2();
}

 

What is GEEK

Buddha Community

When_Async | Utility Classes to Work with Asynchronous Computations

Yashi Tyagi

1617449307

CA Classes - Best CA Classes Online

Chartered Accountancy course requires mental focus & discipline, coaching for CA Foundation, CA Inter and CA Finals are omnipresent, and some of the best faculty’s classes have moved online, in this blog, we are going to give the best way to find online videos lectures, various online websites provide the CA lectures, Smartnstudy one of the best site to CA preparation, here all faculty’s video lecture available.

check here : ca classes

#ca classes online #ca classes in delhi #ca classes app #ca pendrive classes #ca google drive classes #best ca classes online

Alice Cook

Alice Cook

1614329473

Fix: G Suite not Working | G Suite Email not Working | Google Business

G Suite is one of the Google products, developed form of Google Apps. It is a single platform to hold cloud computing, collaboration tools, productivity, software, and products. While using it, many a time, it’s not working, and users have a question– How to fix G Suite not working on iPhone? It can be resolved easily by restarting the device, and if unable to do so, you can reach our specialists whenever you want.
For more details: https://contactforhelp.com/blog/how-to-fix-the-g-suite-email-not-working-issue/

#g suite email not working #g suite email not working on iphone #g suite email not working on android #suite email not working on windows 10 #g suite email not working on mac #g suite email not syncing

Xfinity Stream Not Working?

Xfinity, the tradename of Comcast Cable Communications, LLC, is the first rate supplier of Internet, satellite TV, phone, and remote administrations in the United States. Presented in 2010, previously these administrations were given under the Comcast brand umbrella. Xfinity makes a universe of mind boggling amusement and innovation benefits that joins a great many individuals to the encounters and minutes that issue them the most. Since Xfinity is the greatest supplier of link administrations and home Internet in the United States, it isn’t amazing that the organization gets a ton of investigating and inquiry goal demands on its telephone based Xfinity Customer Service.

#my internet is not working comcast #comcast tv remote not working #my xfinity internet is not working #xfinity stream not working #xfinity wifi hotspot not working

Thurman  Mills

Thurman Mills

1620874140

Cloud Computing Vs Grid Computing

The similarity between cloud computing and grid computing is uncanny. The underlying concepts that make these two inherently different are actually so similar to one and another, which is responsible for creating a lot of confusion. Both cloud and grid computing aims to provide a similar kind of services to a large user base by sharing assets among an enormous pool of clients.

Both of these technologies are obviously network-based and are capable enough to sport multitasking. The availability of multitasking allows the users of either of the two services to use multiple applications at the same time. You are also not limited to the kind of applications that you can use. You are free to choose any number of applications that can accomplish any tasks that you want. Learn more about cloud computing applications.

#cloud computing #cloud computing vs grid computing #grid computing #cloud

Flutter Dev

Flutter Dev

1629625496

When_Async | Utility Classes to Work with Asynchronous 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 same 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.

 

Use this package as a library

Depend on it

Run this command:

With Dart:

 $ dart pub add when_async

With Flutter:

 $ flutter pub add when_async

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):


dependencies:
  when_async: ^1.2.1

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

Import it

Now in your Dart code, you can use:

import 'package:when_async/when_async.dart';

example/when_async_example.dart

import 'dart:io';

import 'package:when_async/when_async.dart';

class FakeError extends Error {}

Future<void> example1() {
  stdout.writeln('Example 1');

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

  final _whenError = When.future<int>(
    () => Future.delayed(
      const Duration(seconds: 5),
      () => throw FakeError(),
    ),
  );

  const _listener1 = '(execute)';

  final task1 = _when.execute(
    onLoading: () => stdout.writeln('$_listener1: Loading'),
    onComplete: (it) => stdout.writeln('$_listener1: Data: $it'),
    onError: (e, s) => stdout.writeln('$_listener1: $e'),
    onFinally: () => stdout.writeln('$_listener1: Finally'),
  );

  const _listener2 = '(executeWithError)';

  final task2 = _whenError.execute(
    onLoading: () => stdout.writeln('$_listener2: Loading'),
    onComplete: (it) => stdout.writeln('$_listener2: Data: $it'),
    onError: (e, s) => stdout.writeln('$_listener2: Error: $e'),
    onFinally: () => stdout.writeln('$_listener2: Finally'),
  );

  return Future.wait([task1, task2]);
}

Future<void> example2() {
  stdout.writeln('Example 2');

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

  final _whenError = When.future<int>(
    () => Future.delayed(
      const Duration(seconds: 5),
      () => throw FakeError(),
    ),
  );

  const _listener1 = '(snapshot)';

  final task1 = _when.snapshots(
    (snapshot) => stdout.writeln('$_listener1: ${snapshot.state}'),
    () => stdout.writeln('$_listener1: Finally'),
  );

  const _listener2 = '(snapshotWithError)';

  final task2 = _whenError.snapshots(
    (snapshot) => stdout.writeln('$_listener2: ${snapshot.state}'),
    () => stdout.writeln('$_listener2: Finally'),
  );

  return Future.wait([task1, task2]);
}

Future<void> main() async {
  await example1();
  await example2();
}