Commit 13deb457 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Modify comments in Future.h to use thenValue, thenTry and thenError rather than then and onError

Summary: Make comments consistent with the updated recommendations where it makes sense.

Reviewed By: yfeldblum

Differential Revision: D9833280

fbshipit-source-id: 8de3372b013a322e57cd2d54a512d75bf963d1a5
parent 56768cc0
...@@ -424,13 +424,13 @@ class FutureBase { ...@@ -424,13 +424,13 @@ class FutureBase {
} }
// Variant: returns a value // Variant: returns a value
// e.g. f.then([](Try<T> t){ return t.value(); }); // e.g. f.thenTry([](Try<T> t){ return t.value(); });
template <typename F, typename R, bool isTry, typename... Args> template <typename F, typename R, bool isTry, typename... Args>
typename std::enable_if<!R::ReturnsFuture::value, typename R::Return>::type typename std::enable_if<!R::ReturnsFuture::value, typename R::Return>::type
thenImplementation(F&& func, futures::detail::argResult<isTry, F, Args...>); thenImplementation(F&& func, futures::detail::argResult<isTry, F, Args...>);
// Variant: returns a Future // Variant: returns a Future
// e.g. f.then([](Try<T> t){ return makeFuture<T>(t); }); // e.g. f.thenTry([](Try<T> t){ return makeFuture<T>(t); });
template <typename F, typename R, bool isTry, typename... Args> template <typename F, typename R, bool isTry, typename... Args>
typename std::enable_if<R::ReturnsFuture::value, typename R::Return>::type typename std::enable_if<R::ReturnsFuture::value, typename R::Return>::type
thenImplementation(F&& func, futures::detail::argResult<isTry, F, Args...>); thenImplementation(F&& func, futures::detail::argResult<isTry, F, Args...>);
...@@ -459,7 +459,7 @@ DeferredExecutor* stealDeferredExecutor(SemiFuture<T>& future); ...@@ -459,7 +459,7 @@ DeferredExecutor* stealDeferredExecutor(SemiFuture<T>& future);
/// - The consumer-side should generally start with a SemiFuture, not a Future. /// - The consumer-side should generally start with a SemiFuture, not a Future.
/// - Example, when a library creates and returns a future, it should usually /// - Example, when a library creates and returns a future, it should usually
/// return a `SemiFuture`, not a Future. /// return a `SemiFuture`, not a Future.
/// - Reason: so the thread policy for continuations (`.then()`, etc.) can be /// - Reason: so the thread policy for continuations (`.thenValue`, etc.) can be
/// specified by the library's caller (using `.via()`). /// specified by the library's caller (using `.via()`).
/// - A SemiFuture is converted to a Future using `.via()`. /// - A SemiFuture is converted to a Future using `.via()`.
/// - Use `makePromiseContract()` when creating both a Promise and an associated /// - Use `makePromiseContract()` when creating both a Promise and an associated
...@@ -467,7 +467,7 @@ DeferredExecutor* stealDeferredExecutor(SemiFuture<T>& future); ...@@ -467,7 +467,7 @@ DeferredExecutor* stealDeferredExecutor(SemiFuture<T>& future);
/// ///
/// When practical, prefer SemiFuture/Future's nonblocking style/pattern: /// When practical, prefer SemiFuture/Future's nonblocking style/pattern:
/// ///
/// - the nonblocking style uses continuations, e.g., `.then()`, etc.; the /// - the nonblocking style uses continuations, e.g., `.thenValue`, etc.; the
/// continuations are deferred until the result is available. /// continuations are deferred until the result is available.
/// - the blocking style blocks until complete, e.g., `.wait()`, `.get()`, etc. /// - the blocking style blocks until complete, e.g., `.wait()`, `.get()`, etc.
/// - the two styles cannot be mixed within the same future; use one or the /// - the two styles cannot be mixed within the same future; use one or the
...@@ -571,7 +571,7 @@ class SemiFuture : private futures::detail::FutureBase<T> { ...@@ -571,7 +571,7 @@ class SemiFuture : private futures::detail::FutureBase<T> {
/// Preconditions: /// Preconditions:
/// ///
/// - `valid() == true` (else throws FutureInvalid) /// - `valid() == true` (else throws FutureInvalid)
/// - must not have a continuation, e.g., via `.then()` or similar /// - must not have a continuation, e.g., via `.thenValue()` or similar
/// ///
/// Postconditions: /// Postconditions:
/// ///
...@@ -933,7 +933,7 @@ std::pair<Promise<T>, SemiFuture<T>> makePromiseContract() { ...@@ -933,7 +933,7 @@ std::pair<Promise<T>, SemiFuture<T>> makePromiseContract() {
/// - The consumer-side should generally start with a SemiFuture, not a Future. /// - The consumer-side should generally start with a SemiFuture, not a Future.
/// - Example, when a library creates and returns a future, it should usually /// - Example, when a library creates and returns a future, it should usually
/// return a `SemiFuture`, not a Future. /// return a `SemiFuture`, not a Future.
/// - Reason: so the thread policy for continuations (`.then()`, etc.) can be /// - Reason: so the thread policy for continuations (`.thenValue`, etc.) can be
/// specified by the library's caller (using `.via()`). /// specified by the library's caller (using `.via()`).
/// - A SemiFuture is converted to a Future using `.via()`. /// - A SemiFuture is converted to a Future using `.via()`.
/// - Use `makePromiseContract()` when creating both a Promise and an associated /// - Use `makePromiseContract()` when creating both a Promise and an associated
...@@ -941,7 +941,7 @@ std::pair<Promise<T>, SemiFuture<T>> makePromiseContract() { ...@@ -941,7 +941,7 @@ std::pair<Promise<T>, SemiFuture<T>> makePromiseContract() {
/// ///
/// When practical, prefer SemiFuture/Future's nonblocking style/pattern: /// When practical, prefer SemiFuture/Future's nonblocking style/pattern:
/// ///
/// - the nonblocking style uses continuations, e.g., `.then()`, etc.; the /// - the nonblocking style uses continuations, e.g., `.thenValue`, etc.; the
/// continuations are deferred until the result is available. /// continuations are deferred until the result is available.
/// - the blocking style blocks until complete, e.g., `.wait()`, `.get()`, etc. /// - the blocking style blocks until complete, e.g., `.wait()`, `.get()`, etc.
/// - the two styles cannot be mixed within the same future; use one or the /// - the two styles cannot be mixed within the same future; use one or the
...@@ -1141,7 +1141,7 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1141,7 +1141,7 @@ class Future : private futures::detail::FutureBase<T> {
/// ///
/// A Future for the return type of func is returned. /// A Future for the return type of func is returned.
/// ///
/// Future<string> f2 = f1.then([](Try<T>&&) { return string("foo"); }); /// Future<string> f2 = f1.thenTry([](Try<T>&&) { return string("foo"); });
/// ///
/// Preconditions: /// Preconditions:
/// ///
...@@ -1190,11 +1190,11 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1190,11 +1190,11 @@ class Future : private futures::detail::FutureBase<T> {
/// struct Worker { R doWork(Try<T>); } /// struct Worker { R doWork(Try<T>); }
/// ///
/// Worker *w; /// Worker *w;
/// Future<R> f2 = f1.then(&Worker::doWork, w); /// Future<R> f2 = f1.thenTry(&Worker::doWork, w);
/// ///
/// This is just sugar for /// This is just sugar for
/// ///
/// f1.then(std::bind(&Worker::doWork, w)); /// f1.thenTry(std::bind(&Worker::doWork, w));
/// ///
/// Preconditions: /// Preconditions:
/// ///
...@@ -1395,7 +1395,7 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1395,7 +1395,7 @@ class Future : private futures::detail::FutureBase<T> {
// clang-format off // clang-format off
[[deprecated( [[deprecated(
"must be rvalue-qualified, e.g., std::move(future).then()")]] "must be rvalue-qualified, e.g., std::move(future).thenValue()")]]
Future<Unit> then() & = delete; Future<Unit> then() & = delete;
// clang-format on // clang-format on
...@@ -1428,7 +1428,7 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1428,7 +1428,7 @@ class Future : private futures::detail::FutureBase<T> {
/// throw std::runtime_error("oh no!"); /// throw std::runtime_error("oh no!");
/// return 42; /// return 42;
/// }) /// })
/// .onError([] (std::runtime_error& e) { /// .thenError<std::runtime_error>([] (std::runtime_error& e) {
/// LOG(INFO) << "std::runtime_error: " << e.what(); /// LOG(INFO) << "std::runtime_error: " << e.what();
/// return -1; // or makeFuture<int>(-1) /// return -1; // or makeFuture<int>(-1)
/// }); /// });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment