Future<T>.syncValue constructor

  1. @Since("3.10")
Future<T>.syncValue(
  1. T value
)

Creates a future completed with value.

The future is guaranteed to not have an error.

If a synchronous computation can throw, rather than doing Future.syncValue(computation()) and wrapping that in a try/catch, you can use Future.sync which catches an error into its returned future, as Future.sync(() => computation()).

Implementation

@Since("3.10")
factory Future.syncValue(T value) => _Future<T>().._setValue(value);