fulfil -> setWith, fulfilTry -> setTry
authorJames Sedgwick <jsedgwick@fb.com>
Thu, 16 Apr 2015 01:23:32 +0000 (18:23 -0700)
committerAlecs King <int@fb.com>
Mon, 27 Apr 2015 23:41:50 +0000 (16:41 -0700)
Summary: title

Test Plan: tests

Reviewed By: hans@fb.com

Subscribers: cgist, cold-storage-diffs@, fugalh, atlas2-eng@, zhuohuang, folly-diffs@, jsedgwick, yfeldblum, chalfant, andrii

FB internal diff: D1994472

Tasks: 6768508

Signature: t1:1994472:1429117362:218c4fac3c88fcc8d37dc22ff8fe4135a73ec5d5

12 files changed:
folly/experimental/fibers/Promise-inl.h
folly/experimental/fibers/Promise.h
folly/futures/Future-inl.h
folly/futures/Promise-inl.h
folly/futures/Promise.h
folly/futures/README.md
folly/futures/detail/Core.h
folly/futures/test/Benchmark.cpp
folly/futures/test/FutureTest.cpp
folly/futures/test/SugarTest.cpp
folly/wangle/channel/OutputBufferingHandler.h
folly/wangle/concurrent/FutureExecutor.h

index 6b1aae1303ece87e76e47151268c2bff37705ca3..b7e92b561b781286f00c03a7dc8f696d226846ad 100644 (file)
@@ -53,11 +53,11 @@ Promise<T>::~Promise() {
 
 template <class T>
 void Promise<T>::setException(folly::exception_wrapper e) {
-  fulfilTry(folly::Try<T>(e));
+  setTry(folly::Try<T>(e));
 }
 
 template <class T>
-void Promise<T>::fulfilTry(folly::Try<T>&& t) {
+void Promise<T>::setTry(folly::Try<T>&& t) {
   throwIfFulfilled();
 
   *value_ = std::move(t);
@@ -73,7 +73,7 @@ void Promise<T>::setValue(M&& v) {
   static_assert(!std::is_same<T, void>::value,
                 "Use setValue() instead");
 
-  fulfilTry(folly::Try<T>(std::forward<M>(v)));
+  setTry(folly::Try<T>(std::forward<M>(v)));
 }
 
 template <class T>
@@ -81,13 +81,13 @@ void Promise<T>::setValue() {
   static_assert(std::is_same<T, void>::value,
                 "Use setValue(value) instead");
 
-  fulfilTry(folly::Try<void>());
+  setTry(folly::Try<void>());
 }
 
 template <class T>
 template <class F>
-void Promise<T>::fulfil(F&& func) {
-  fulfilTry(makeTryFunction(std::forward<F>(func)));
+void Promise<T>::setWith(F&& func) {
+  setTry(makeTryFunction(std::forward<F>(func)));
 }
 
 }}
index 7d24821da1560786902c07b4cc536793c8d92986..e8de0abb9eb5c9a02f1de64ed8bc8f79219a62b9 100644 (file)
@@ -41,7 +41,7 @@ class Promise {
   Promise(Promise&&) noexcept;
   Promise& operator=(Promise&&);
 
-  /** Fulfil this promise (only for Promise<void>) */
+  /** Fulfill this promise (only for Promise<void>) */
   void setValue();
 
   /** Set the value (use perfect forwarding for both move and copy) */
@@ -53,18 +53,18 @@ class Promise {
    *
    * @param t
    */
-  void fulfilTry(folly::Try<T>&& t);
+  void setTry(folly::Try<T>&& t);
 
-  /** Fulfil this promise with the result of a function that takes no
+  /** Fulfill this promise with the result of a function that takes no
     arguments and returns something implicitly convertible to T.
     Captures exceptions. e.g.
 
-    p.fulfil([] { do something that may throw; return a T; });
+    p.setWith([] { do something that may throw; return a T; });
   */
   template <class F>
-  void fulfil(F&& func);
+  void setWith(F&& func);
 
-  /** Fulfil the Promise with an exception_wrapper, e.g.
+  /** Fulfill the Promise with an exception_wrapper, e.g.
     auto ew = folly::try_and_catch<std::exception>([]{ ... });
     if (ew) {
       p.setException(std::move(ew));
index ffa22ad6d7d8b645225d0f5b918b621b181d530f..0a616a86836aba5d391a5272794ebf3acae9d145 100644 (file)
@@ -171,7 +171,7 @@ Future<T>::thenImplementation(F func, detail::argResult<isTry, F, Args...>) {
       if (!isTry && t.hasException()) {
         p->setException(std::move(t.exception()));
       } else {
-        p->fulfil([&]() {
+        p->setWith([&]() {
           return (*funcm)(t.template get<isTry, Args>()...);
         });
       }
@@ -210,7 +210,7 @@ Future<T>::thenImplementation(F func, detail::argResult<isTry, F, Args...>) {
           auto f2 = (*funcm)(t.template get<isTry, Args>()...);
           // that didn't throw, now we can steal p
           f2.setCallback_([p](Try<B>&& b) mutable {
-            p->fulfilTry(std::move(b));
+            p->setTry(std::move(b));
           });
         } catch (const std::exception& e) {
           p->setException(exception_wrapper(std::current_exception(), e));
@@ -259,11 +259,11 @@ Future<T>::onError(F&& func) {
   auto funcm = folly::makeMoveWrapper(std::move(func));
   setCallback_([pm, funcm](Try<T>&& t) mutable {
     if (!t.template withException<Exn>([&] (Exn& e) {
-          pm->fulfil([&]{
+          pm->setWith([&]{
             return (*funcm)(e);
           });
         })) {
-      pm->fulfilTry(std::move(t));
+      pm->setTry(std::move(t));
     }
   });
 
@@ -292,7 +292,7 @@ Future<T>::onError(F&& func) {
           try {
             auto f2 = (*funcm)(e);
             f2.setCallback_([pm](Try<T>&& t2) mutable {
-              pm->fulfilTry(std::move(t2));
+              pm->setTry(std::move(t2));
             });
           } catch (const std::exception& e2) {
             pm->setException(exception_wrapper(std::current_exception(), e2));
@@ -300,7 +300,7 @@ Future<T>::onError(F&& func) {
             pm->setException(exception_wrapper(std::current_exception()));
           }
         })) {
-      pm->fulfilTry(std::move(t));
+      pm->setTry(std::move(t));
     }
   });
 
@@ -436,7 +436,7 @@ inline Future<T> Future<T>::via(Executor* executor) & {
 
   MoveWrapper<Promise<T>> p;
   auto f = p->getFuture();
-  then([p](Try<T>&& t) mutable { p->fulfilTry(std::move(t)); });
+  then([p](Try<T>&& t) mutable { p->setTry(std::move(t)); });
   return std::move(f).via(executor);
 }
 
@@ -473,7 +473,7 @@ auto makeFutureTry(
     typename std::enable_if<!std::is_reference<F>::value, bool>::type sdf)
     -> Future<decltype(func())> {
   Promise<decltype(func())> p;
-  p.fulfil(
+  p.setWith(
     [&func]() {
       return (func)();
     });
@@ -512,7 +512,7 @@ makeFuture(E const& e) {
 template <class T>
 Future<T> makeFuture(Try<T>&& t) {
   Promise<typename std::decay<T>::type> p;
-  p.fulfilTry(std::move(t));
+  p.setTry(std::move(t));
   return p.getFuture();
 }
 
@@ -627,7 +627,7 @@ whenN(InputIterator first, InputIterator last, size_t n) {
   ctx->completed = 0;
 
   // for each completed Future, increase count and add to vector, until we
-  // have n completed futures at which point we fulfil our Promise with the
+  // have n completed futures at which point we fulfill our Promise with the
   // vector
   auto it = first;
   size_t i = 0;
@@ -639,7 +639,7 @@ whenN(InputIterator first, InputIterator last, size_t n) {
         assert(ctx->v.size() < n);
         v.push_back(std::make_pair(i, std::move(t)));
         if (c == n) {
-          ctx->p.fulfilTry(Try<V>(std::move(v)));
+          ctx->p.setTry(Try<V>(std::move(v)));
         }
       }
     });
@@ -736,7 +736,7 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) {
 
   this->then([ctx](Try<T>&& t) {
     if (ctx->token.exchange(true) == false) {
-      ctx->promise.fulfilTry(std::move(t));
+      ctx->promise.setTry(std::move(t));
     }
   });
 
@@ -923,7 +923,7 @@ namespace futures {
     MoveWrapper<Promise<A>> pw;
     MoveWrapper<Future<Z>> fw(chainHelper<Z>(pw->getFuture(), fns...));
     return [=](Try<A> t) mutable {
-      pw->fulfilTry(std::move(t));
+      pw->setTry(std::move(t));
       return std::move(*fw);
     };
   }
index b57e952f93a4161911519828b8d6382a26fe8674..6f5a7d1a5a141f3645f44d6aa0b36d6cb5edbf6e 100644 (file)
@@ -109,7 +109,7 @@ void Promise<T>::setInterruptHandler(
 }
 
 template <class T>
-void Promise<T>::fulfilTry(Try<T> t) {
+void Promise<T>::setTry(Try<T> t) {
   throwIfFulfilled();
   core_->setResult(std::move(t));
 }
@@ -120,7 +120,7 @@ void Promise<T>::setValue(M&& v) {
   static_assert(!std::is_same<T, void>::value,
                 "Use setValue() instead");
 
-  fulfilTry(Try<T>(std::forward<M>(v)));
+  setTry(Try<T>(std::forward<M>(v)));
 }
 
 template <class T>
@@ -128,14 +128,14 @@ void Promise<T>::setValue() {
   static_assert(std::is_same<T, void>::value,
                 "Use setValue(value) instead");
 
-  fulfilTry(Try<void>());
+  setTry(Try<void>());
 }
 
 template <class T>
 template <class F>
-void Promise<T>::fulfil(F&& func) {
+void Promise<T>::setWith(F&& func) {
   throwIfFulfilled();
-  fulfilTry(makeTryFunction(std::forward<F>(func)));
+  setTry(makeTryFunction(std::forward<F>(func)));
 }
 
 }
index a38d6f1c82604401f104b215f65f8e4c14ea8a96..e39ea57f0d2ff9e06ae11547ee9a7994666f109b 100644 (file)
@@ -43,10 +43,10 @@ public:
     once, thereafter Future already retrieved exception will be raised. */
   Future<T> getFuture();
 
-  /** Fulfil the Promise with an exception_wrapper */
+  /** Fulfill the Promise with an exception_wrapper */
   void setException(exception_wrapper ew);
 
-  /** Fulfil the Promise with an exception_ptr, e.g.
+  /** Fulfill the Promise with an exception_ptr, e.g.
     try {
       ...
     } catch (...) {
@@ -55,7 +55,7 @@ public:
     */
   void setException(std::exception_ptr const&) DEPRECATED;
 
-  /** Fulfil the Promise with an exception type E, which can be passed to
+  /** Fulfill the Promise with an exception type E, which can be passed to
     std::make_exception_ptr(). Useful for originating exceptions. If you
     caught an exception the exception_wrapper form is more appropriate.
     */
@@ -65,28 +65,28 @@ public:
 
   /// Set an interrupt handler to handle interrupts. See the documentation for
   /// Future::raise(). Your handler can do whatever it wants, but if you
-  /// bother to set one then you probably will want to fulfil the promise with
+  /// bother to set one then you probably will want to fulfill the promise with
   /// an exception (or special value) indicating how the interrupt was
   /// handled.
   void setInterruptHandler(std::function<void(exception_wrapper const&)>);
 
-  /** Fulfil this Promise (only for Promise<void>) */
+  /** Fulfill this Promise (only for Promise<void>) */
   void setValue();
 
   /** Set the value (use perfect forwarding for both move and copy) */
   template <class M>
   void setValue(M&& value);
 
-  void fulfilTry(Try<T> t);
+  void setTry(Try<T> t);
 
-  /** Fulfil this Promise with the result of a function that takes no
+  /** Fulfill this Promise with the result of a function that takes no
     arguments and returns something implicitly convertible to T.
     Captures exceptions. e.g.
 
-    p.fulfil([] { do something that may throw; return a T; });
+    p.setWith([] { do something that may throw; return a T; });
   */
   template <class F>
-  void fulfil(F&& func);
+  void setWith(F&& func);
 
 private:
   typedef typename Future<T>::corePtr corePtr;
index 013e78c86c1d5dd1e37a2c806c93582ae098042c..741fa2343c86b5f9e113077761053bb4758f04bd 100644 (file)
@@ -193,7 +193,7 @@ f2.then(y3); // racy
 
 ## You make me Promises, Promises
 
-If you are wrapping an asynchronous operation, or providing an asynchronous API to users, then you will want to make Promises. Every Future has a corresponding Promise (except Futures that spring into existence already completed, with `makeFuture()`). Promises are simple, you make one, you extract the Future, and you fulfil it with a value or an exception. Example:
+If you are wrapping an asynchronous operation, or providing an asynchronous API to users, then you will want to make Promises. Every Future has a corresponding Promise (except Futures that spring into existence already completed, with `makeFuture()`). Promises are simple, you make one, you extract the Future, and you fulfill it with a value or an exception. Example:
 
 ```C++
 Promise<int> p;
@@ -221,11 +221,11 @@ f.isReady() == true
 f.value() // throws the exception
 ```
 
-It's good practice to use fulfil which takes a function and automatically captures exceptions, e.g.
+It's good practice to use setWith which takes a function and automatically captures exceptions, e.g.
 
 ```C++
 Promise<int> p;
-p.fulfil([]{
+p.setWith([]{
   try {
     // do stuff that may throw
     return 42;
index 4bdc5ef4755e05f20ef761420d1510fdb2e966ba..037ad138540f6f586ba51a16f28c9e2c10a45a4c 100644 (file)
@@ -68,7 +68,7 @@ enum class State : uint8_t {
 /// migrate between threads, though this usually happens within the API code.
 /// For example, an async operation will probably make a Promise, grab its
 /// Future, then move the Promise into another thread that will eventually
-/// fulfil it. With executors and via, this gets slightly more complicated at
+/// fulfill it. With executors and via, this gets slightly more complicated at
 /// first blush, but it's the same principle. In general, as long as the user
 /// doesn't access a Future or Promise object from more than one thread at a
 /// time there won't be any problems.
index 053d4d9d07c3b87147b1fc5310da3551c2267abf..fbf2538fa7e0fcc54cebe2ca45d4493a058e4850 100644 (file)
@@ -83,7 +83,7 @@ BENCHMARK_RELATIVE(hundredThens) {
   someThens(100);
 }
 
-// Lock contention. Although in practice fulfil()s tend to be temporally
+// Lock contention. Although in practice fulfills tend to be temporally
 // separate from then()s, still sometimes they will be concurrent. So the
 // higher this number is, the better.
 BENCHMARK_DRAW_LINE()
@@ -113,7 +113,7 @@ BENCHMARK(no_contention) {
     b2.wait();
   }
 
-  // The only thing we are measuring is how long fulfil + callbacks take
+  // The only thing we are measuring is how long fulfill + callbacks take
   producer.join();
 }
 
index 01e637699bbfab69b55eed58b6c9f199363d430b..c74458ac0cf38eeff3a894277db7605c9db898b1 100644 (file)
@@ -617,17 +617,17 @@ TEST(Promise, setException) {
   }
 }
 
-TEST(Promise, fulfil) {
+TEST(Promise, setWith) {
   {
     Promise<int> p;
     auto f = p.getFuture();
-    p.fulfil([] { return 42; });
+    p.setWith([] { return 42; });
     EXPECT_EQ(42, f.value());
   }
   {
     Promise<int> p;
     auto f = p.getFuture();
-    p.fulfil([]() -> int { throw eggs; });
+    p.setWith([]() -> int { throw eggs; });
     EXPECT_THROW(f.value(), eggs_t);
   }
 }
@@ -1240,7 +1240,7 @@ TEST(Future, getFuture_after_setValue) {
 
 TEST(Future, getFuture_after_setException) {
   Promise<void> p;
-  p.fulfil([]() -> void { throw std::logic_error("foo"); });
+  p.setWith([]() -> void { throw std::logic_error("foo"); });
   EXPECT_THROW(p.getFuture().value(), std::logic_error);
 }
 
@@ -1302,7 +1302,7 @@ TEST(Future, context) {
 
   EXPECT_EQ(nullptr, RequestContext::get()->getContextData("test"));
 
-  // Fulfil the promise
+  // Fulfill the promise
   p.setValue();
 }
 
@@ -1354,7 +1354,7 @@ TEST(Future, CircularDependencySharedPtrSelfReset) {
 
   ptr.reset();
 
-  promise.fulfil([]{return 1l;});
+  promise.setWith([]{return 1l;});
 }
 
 TEST(Future, Constructor) {
index bbafdebbda415fa54310c497dd011e2b4fd3f1da..0563eef41b6f0cab22b6b5a81e76e525fd1413e4 100644 (file)
@@ -36,7 +36,7 @@ TEST(Sugar, pollNotReady) {
 TEST(Sugar, pollException) {
   Promise<void> p;
   auto f = p.getFuture();
-  p.fulfil([] { throw std::runtime_error("Runtime"); });
+  p.setWith([] { throw std::runtime_error("Runtime"); });
   EXPECT_TRUE(f.poll().value().hasException());
 }
 
index a1165ca1286f322e16d0ab2b0ed026a72f3285a3..e5ca99aee94bbc01fe8fda8af8b970ad7751fde0 100644 (file)
@@ -58,7 +58,7 @@ class OutputBufferingHandler : public BytesToBytesHandler,
     MoveWrapper<std::vector<Promise<void>>> promises(std::move(promises_));
     ctx_->fireWrite(std::move(sends_)).then([promises](Try<void> t) mutable {
       for (auto& p : *promises) {
-        p.fulfilTry(t);
+        p.setTry(t);
       }
     });
   }
index e850f3a0c2f967227b007e87fe677c87ee97a5df..cbf4123a92db710b0fe15e59ef9e90ab95534657 100644 (file)
@@ -46,7 +46,7 @@ class FutureExecutor : public ExecutorImpl {
     auto moveFunc = folly::makeMoveWrapper(std::move(func));
     ExecutorImpl::add([movePromise, moveFunc] () mutable {
       (*moveFunc)().then([movePromise] (Try<T>&& t) mutable {
-        movePromise->fulfilTry(std::move(t));
+        movePromise->setTry(std::move(t));
       });
     });
     return future;
@@ -70,7 +70,7 @@ class FutureExecutor : public ExecutorImpl {
     auto movePromise = folly::makeMoveWrapper(std::move(promise));
     auto moveFunc = folly::makeMoveWrapper(std::move(func));
     ExecutorImpl::add([movePromise, moveFunc] () mutable {
-      movePromise->fulfil(std::move(*moveFunc));
+      movePromise->setWith(std::move(*moveFunc));
     });
     return future;
   }