useStorageWithHandlers<R> method
- @protected
- @nonVirtual
Calling block
with S
as argument.
Implementation
@protected
@nonVirtual
Future<R> useStorageWithHandlers<R>(
Future<R> Function(S) block,
FutureOr<void> Function(R, S)? onSuccess,
FutureOr<void> Function(RxStorageError, S)? onFailure,
) async {
assert(_debugAssertNotDisposed());
final storage = _storage ?? await _storageFuture;
if (onSuccess == null && onFailure == null) {
return await block(storage);
}
try {
final value = await block(storage);
final futureOrVoid = onSuccess?.call(value, storage);
if (futureOrVoid is Future<void>) {
await futureOrVoid;
}
return value;
} catch (e, s) {
final futureOrVoid = onFailure?.call(RxStorageError(e, s), storage);
if (futureOrVoid is Future<void>) {
await futureOrVoid;
}
rethrow;
}
}