asynchronous top-level constant

Asynchronous const asynchronous

Annotates a module provider method that returns a Future.

Such a provider is referred to as asynchronous provider. Asynchronous providers are resolved from futures into dependency instances prior to returning the injector to the application.

Example:

@module
abstract class CarModule {
  @provide
  @asynchronous
  Future<Car> provideCar();
}

class Dealership {
  @provide
  Dealership(Car car);
}

Note that in the example Dealership depends on Car rather than Future<Car>. This is the quintessential property of the asynchronous annotation. It guarantees that Future<Car> is resolved into Car prior to instantiating objects that depend on it.

If you wish to inject the Future itself without resolving it, simply omit this annotation and the Future will be treated as a normal type, and the framework will not attempt to resolve it.

Example:

@module
abstract class CarModule {
  @provide
  Future<Car> provideCar();
}

class Dealership {
  @provide
  Dealership(Future<Car> car);
}

Implementation

const asynchronous = const Asynchronous._();