safeUpdateAsync<T> static method

Future<T?> safeUpdateAsync<T>(
  1. Future<T> update(), {
  2. T? fallback,
})

Execute an async function safely, returning fallback on error

Implementation

static Future<T?> safeUpdateAsync<T>(
  Future<T> Function() update, {
  T? fallback,
}) async {
  try {
    return await update();
  } catch (e, stackTrace) {
    Logger.error('Async state update error', e);
    Logger.debug('Stack trace', stackTrace);
    return fallback;
  }
}