PollableFuture<T> constructor

PollableFuture<T>(
  1. FutureOr<T> futureOrValue
)

Constructor.

If futureOrValue is not a Future, then the PollableFuture will be constructed in the completed state with that value.

If futureOrValue is a Future, regardless of whether that Future is already completed or not, then the PollableFuture will mark itself completed only after that Future executes its Future.then callbacks.

Alternatively use the PollableFutureExtension.toPollable extension method on an existing Future.

Implementation

PollableFuture(FutureOr<T> futureOrValue) : _futureOrValue = futureOrValue {
  if (_futureOrValue case Future<T> future) {
    unawaited(
      future.then((value) {
        _futureOrValue = value;
      }),
    );
  }
}