AsyncValue<T>.from constructor

AsyncValue<T>.from(
  1. Object? value
)

Implementation

factory AsyncValue.from(Object? value) {
  if (value is Future) {
    return AsyncValue(value as Future<T>);
  } else if (value is Future<T> Function()) {
    var future = value();
    return AsyncValue<T>(future);
  } else if (value is Future Function()) {
    var future = value();
    return AsyncValue(future as Future<T>);
  } else if (value is T Function()) {
    var future = Future.microtask(() => value());
    return AsyncValue<T>(future);
  } else if (value is Function) {
    var future = Future.microtask(() async {
      var result = value();
      if (result is Future) {
        var result2 = await result;
        return result2;
      } else {
        return result;
      }
    });
    return AsyncValue(future as Future<T>);
  } else {
    throw ArgumentError('Not an async value: $value');
  }
}