tryRunEither<T> static method

FutureOr<KResult<T>> tryRunEither<T>(
  1. FutureOr<T?> operation(), {
  2. bool logError = true,
})

Implementation

static FutureOr<KResult<T>> tryRunEither<T>(FutureOr<T?> Function() operation, {bool logError = true}) async {
  try {
    return KResult.success((await operation()) as T);
  } catch (e, st) {
    if (logError) {
      log("Result tryRunEither error: ${e.toString()}", error: e, stackTrace: st);
    }
    return KResult.error(e.toString(), st, logError);
  }
}