From 98c488e23b44105d0e1a5b1d5cd7dea10b5843d5 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Thu, 9 Nov 2017 13:34:35 -0800 Subject: [PATCH] Add makeSemiFuture declarations to helpers.h Summary: [Folly] Add `makeSemiFuture` declarations to `helpers.h`. For consistency with the `makeFuture` declarations that are also there. Definitions for both are found in `Future-inl.h`. Reviewed By: LeeHowes Differential Revision: D6281826 fbshipit-source-id: 4b22dd9086d05dbdebba358c6f569a772017949a --- folly/futures/helpers.h | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/folly/futures/helpers.h b/folly/futures/helpers.h index a5198e71..9b5e85ba 100644 --- a/folly/futures/helpers.h +++ b/folly/futures/helpers.h @@ -110,6 +110,73 @@ namespace futures { } // namespace futures +/** + Make a completed SemiFuture by moving in a value. e.g. + + string foo = "foo"; + auto f = makeSemiFuture(std::move(foo)); + + or + + auto f = makeSemiFuture("foo"); +*/ +template +SemiFuture::type> makeSemiFuture(T&& t); + +/** Make a completed void SemiFuture. */ +SemiFuture makeSemiFuture(); + +/** + Make a SemiFuture by executing a function. + + If the function returns a value of type T, makeSemiFutureWith + returns a completed SemiFuture, capturing the value returned + by the function. + + If the function returns a SemiFuture already, makeSemiFutureWith + returns just that. + + Either way, if the function throws, a failed Future is + returned that captures the exception. +*/ + +// makeSemiFutureWith(SemiFuture()) -> SemiFuture +template +typename std::enable_if::type>::value, + typename std::result_of::type>::type +makeSemiFutureWith(F&& func); + +// makeSemiFutureWith(T()) -> SemiFuture +// makeSemiFutureWith(void()) -> SemiFuture +template +typename std::enable_if< + !(isSemiFuture::type>::value), + SemiFuture::type>::type>>::type +makeSemiFutureWith(F&& func); + +/// Make a failed Future from an exception_ptr. +/// Because the Future's type cannot be inferred you have to specify it, e.g. +/// +/// auto f = makeSemiFuture(std::current_exception()); +template +FOLLY_DEPRECATED("use makeSemiFuture(exception_wrapper)") +SemiFuture makeSemiFuture(std::exception_ptr const& e); + +/// Make a failed SemiFuture from an exception_wrapper. +template +SemiFuture makeSemiFuture(exception_wrapper ew); + +/** Make a SemiFuture from an exception type E that can be passed to + std::make_exception_ptr(). */ +template +typename std::enable_if::value, + SemiFuture>::type +makeSemiFuture(E const& e); + +/** Make a Future out of a Try */ +template +SemiFuture makeSemiFuture(Try&& t); + /** Make a completed Future by moving in a value. e.g. -- 2.34.1