getIfAvailable method

Future<ObjectHolder<T>?> getIfAvailable([
  1. Supplier<ObjectHolder<T>>? supplier
])

Retrieves the object if available, or returns null if none exist.

Implementation

Future<ObjectHolder<T>?> getIfAvailable([Supplier<ObjectHolder<T>>? supplier]) async {
  ObjectHolder<T>? result;

  try {
    result = await get();
  } on NoUniquePodDefinitionException catch(_) {
    rethrow;
  } on NoSuchPodDefinitionException catch(_) {
    result = null;
  }

  return result ?? supplier?.call();
}