onComplete method
Future<T?>
onComplete({
- required FutureOr<
void> onSuccess(- T r
- required FutureOr<
void> onError(- Object e,
- StackTrace s
- AsyncExtensionErrorLogger? errorLogger,
- bool logError = true,
Calls onSuccess
or onError
when this Future completes.
Logs the error using errorLogger
or defaultAsyncExtensionErrorLogger
if parameter logError
is true
.
Implementation
Future<T?> onComplete({
required FutureOr<void> Function(T r) onSuccess,
required FutureOr<void> Function(Object e, StackTrace s) onError,
AsyncExtensionErrorLogger? errorLogger,
bool logError = true,
}) async {
try {
var r = await this;
await onSuccess(r);
return r;
} catch (e, s) {
if (logError) errorLogger.logError(e, s);
await onError(e, s);
return null;
}
}