executeWithPool<R> method
FutureOr<R>
executeWithPool<R>(
- FutureOr<
R> f(- C o
- Duration? timeout,
- bool validator(
- C o
- dynamic onError(
- Object error,
- StackTrace stackTrace
inherited
Implementation
FutureOr<R> executeWithPool<R>(
FutureOr<R> Function(O o) f, {
Duration? timeout,
bool Function(O o)? validator,
Function(Object error, StackTrace stackTrace)? onError,
}) {
return catchFromPool(timeout: timeout).then((o) {
try {
var ret = f(o);
return ret.then(
(val) {
if (validator == null || validator(o)) {
releaseIntoPool(o);
} else {
disposePoolElement(o);
}
return val;
},
onError: (e, s) {
disposePoolElement(o);
if (onError != null) {
return onError(e, s);
} else {
throw e;
}
},
);
} catch (e, s) {
disposePoolElement(o);
if (onError != null) {
return onError(e, s);
} else {
rethrow;
}
}
});
}