template <class F>
Future<T> Future<T>::ensure(F&& func) {
return this->then([funcw = std::forward<F>(func)](Try<T> && t) mutable {
- funcw();
+ std::move(funcw)();
return makeFuture(std::move(t));
});
}
template <class F>
Future<T> Future<T>::onTimeout(Duration dur, F&& func, Timekeeper* tk) {
return within(dur, tk).onError([funcw = std::forward<F>(func)](
- TimedOut const&) { return funcw(); });
+ TimedOut const&) { return std::move(funcw)(); });
}
template <class T>
template <class Func>
auto via(Executor* x, Func&& func)
- -> Future<typename isFuture<decltype(func())>::Inner>
-{
+ -> Future<typename isFuture<decltype(std::declval<Func>()())>::Inner> {
// TODO make this actually more performant. :-P #7260175
return via(x).then(std::forward<Func>(func));
}
using InnerType =
typename isFuture<typename std::result_of<F()>::type>::Inner;
try {
- return func();
+ return std::forward<F>(func)();
} catch (std::exception& e) {
return makeFuture<InnerType>(
exception_wrapper(std::current_exception(), e));
makeFutureWith(F&& func) {
using LiftedResult =
typename Unit::Lift<typename std::result_of<F()>::type>::type;
- return makeFuture<LiftedResult>(makeTryWith([&func]() mutable {
- return func();
- }));
+ return makeFuture<LiftedResult>(
+ makeTryWith([&func]() mutable { return std::forward<F>(func)(); }));
}
template <class T>
auto ctx = std::make_shared<detail::CollectAllVariadicContext<
typename std::decay<Fs>::type::value_type...>>();
detail::collectVariadicHelper<detail::CollectAllVariadicContext>(
- ctx, std::forward<typename std::decay<Fs>::type>(fs)...);
+ ctx, std::forward<Fs>(fs)...);
return ctx->p.getFuture();
}
auto ctx = std::make_shared<detail::CollectVariadicContext<
typename std::decay<Fs>::type::value_type...>>();
detail::collectVariadicHelper<detail::CollectVariadicContext>(
- ctx, std::forward<typename std::decay<Fs>::type>(fs)...);
+ ctx, std::forward<Fs>(fs)...);
return ctx->p.getFuture();
}
typename THead, typename... TTail>
void collectVariadicHelper(const std::shared_ptr<T<Ts...>>& ctx,
THead&& head, TTail&&... tail) {
- head.setCallback_([ctx](Try<typename THead::value_type>&& t) {
- ctx->template setPartialResult<typename THead::value_type,
- sizeof...(Ts) - sizeof...(TTail) - 1>(t);
+ using ValueType = typename std::decay<THead>::type::value_type;
+ std::forward<THead>(head).setCallback_([ctx](Try<ValueType>&& t) {
+ ctx->template setPartialResult<
+ ValueType,
+ sizeof...(Ts) - sizeof...(TTail)-1>(t);
});
// template tail-recursion
collectVariadicHelper(ctx, std::forward<TTail>(tail)...);
/// easier to read and slightly more efficient.
template <class Func>
auto via(Executor*, Func&& func)
- -> Future<typename isFuture<decltype(func())>::Inner>;
+ -> Future<typename isFuture<decltype(std::declval<Func>()())>::Inner>;
/** When all the input Futures complete, the returned Future will complete.
Errors do not cause early termination; this Future will always succeed