addFuture<T> method
Implementation
VoidCallback addFuture<T>(Future<T> future,
{DataCallback<T>? onData, ErrorCallback? onError}) =>
addSubscription((removeSubscription) {
bool canceled = false;
future.then(
onData == null
? (value) {
if (canceled) return;
removeSubscription();
}
: (value) {
if (canceled) return;
removeSubscription();
onData(value);
},
onError: onError == null
? (error, stackTrace) {
if (canceled) return;
removeSubscription();
Error.throwWithStackTrace(error, stackTrace);
}
: (error, stackTrace) {
removeSubscription();
return onError(error, stackTrace);
});
return () => canceled = true;
});