From: James Sedgwick Date: Thu, 16 Apr 2015 01:23:32 +0000 (-0700) Subject: fulfil -> setWith, fulfilTry -> setTry X-Git-Tag: v0.36.0~36 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a0a9fc4547c535b3bb0dd7192dc065ee1cedcc82;p=folly.git fulfil -> setWith, fulfilTry -> setTry 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 --- diff --git a/folly/experimental/fibers/Promise-inl.h b/folly/experimental/fibers/Promise-inl.h index 6b1aae13..b7e92b56 100644 --- a/folly/experimental/fibers/Promise-inl.h +++ b/folly/experimental/fibers/Promise-inl.h @@ -53,11 +53,11 @@ Promise::~Promise() { template void Promise::setException(folly::exception_wrapper e) { - fulfilTry(folly::Try(e)); + setTry(folly::Try(e)); } template -void Promise::fulfilTry(folly::Try&& t) { +void Promise::setTry(folly::Try&& t) { throwIfFulfilled(); *value_ = std::move(t); @@ -73,7 +73,7 @@ void Promise::setValue(M&& v) { static_assert(!std::is_same::value, "Use setValue() instead"); - fulfilTry(folly::Try(std::forward(v))); + setTry(folly::Try(std::forward(v))); } template @@ -81,13 +81,13 @@ void Promise::setValue() { static_assert(std::is_same::value, "Use setValue(value) instead"); - fulfilTry(folly::Try()); + setTry(folly::Try()); } template template -void Promise::fulfil(F&& func) { - fulfilTry(makeTryFunction(std::forward(func))); +void Promise::setWith(F&& func) { + setTry(makeTryFunction(std::forward(func))); } }} diff --git a/folly/experimental/fibers/Promise.h b/folly/experimental/fibers/Promise.h index 7d24821d..e8de0abb 100644 --- a/folly/experimental/fibers/Promise.h +++ b/folly/experimental/fibers/Promise.h @@ -41,7 +41,7 @@ class Promise { Promise(Promise&&) noexcept; Promise& operator=(Promise&&); - /** Fulfil this promise (only for Promise) */ + /** Fulfill this promise (only for Promise) */ 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); + void setTry(folly::Try&& 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 - 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([]{ ... }); if (ew) { p.setException(std::move(ew)); diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index ffa22ad6..0a616a86 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -171,7 +171,7 @@ Future::thenImplementation(F func, detail::argResult) { if (!isTry && t.hasException()) { p->setException(std::move(t.exception())); } else { - p->fulfil([&]() { + p->setWith([&]() { return (*funcm)(t.template get()...); }); } @@ -210,7 +210,7 @@ Future::thenImplementation(F func, detail::argResult) { auto f2 = (*funcm)(t.template get()...); // that didn't throw, now we can steal p f2.setCallback_([p](Try&& 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::onError(F&& func) { auto funcm = folly::makeMoveWrapper(std::move(func)); setCallback_([pm, funcm](Try&& t) mutable { if (!t.template withException([&] (Exn& e) { - pm->fulfil([&]{ + pm->setWith([&]{ return (*funcm)(e); }); })) { - pm->fulfilTry(std::move(t)); + pm->setTry(std::move(t)); } }); @@ -292,7 +292,7 @@ Future::onError(F&& func) { try { auto f2 = (*funcm)(e); f2.setCallback_([pm](Try&& 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::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 Future::via(Executor* executor) & { MoveWrapper> p; auto f = p->getFuture(); - then([p](Try&& t) mutable { p->fulfilTry(std::move(t)); }); + then([p](Try&& t) mutable { p->setTry(std::move(t)); }); return std::move(f).via(executor); } @@ -473,7 +473,7 @@ auto makeFutureTry( typename std::enable_if::value, bool>::type sdf) -> Future { Promise p; - p.fulfil( + p.setWith( [&func]() { return (func)(); }); @@ -512,7 +512,7 @@ makeFuture(E const& e) { template Future makeFuture(Try&& t) { Promise::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(std::move(v))); + ctx->p.setTry(Try(std::move(v))); } } }); @@ -736,7 +736,7 @@ Future Future::within(Duration dur, E e, Timekeeper* tk) { this->then([ctx](Try&& 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> pw; MoveWrapper> fw(chainHelper(pw->getFuture(), fns...)); return [=](Try t) mutable { - pw->fulfilTry(std::move(t)); + pw->setTry(std::move(t)); return std::move(*fw); }; } diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index b57e952f..6f5a7d1a 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -109,7 +109,7 @@ void Promise::setInterruptHandler( } template -void Promise::fulfilTry(Try t) { +void Promise::setTry(Try t) { throwIfFulfilled(); core_->setResult(std::move(t)); } @@ -120,7 +120,7 @@ void Promise::setValue(M&& v) { static_assert(!std::is_same::value, "Use setValue() instead"); - fulfilTry(Try(std::forward(v))); + setTry(Try(std::forward(v))); } template @@ -128,14 +128,14 @@ void Promise::setValue() { static_assert(std::is_same::value, "Use setValue(value) instead"); - fulfilTry(Try()); + setTry(Try()); } template template -void Promise::fulfil(F&& func) { +void Promise::setWith(F&& func) { throwIfFulfilled(); - fulfilTry(makeTryFunction(std::forward(func))); + setTry(makeTryFunction(std::forward(func))); } } diff --git a/folly/futures/Promise.h b/folly/futures/Promise.h index a38d6f1c..e39ea57f 100644 --- a/folly/futures/Promise.h +++ b/folly/futures/Promise.h @@ -43,10 +43,10 @@ public: once, thereafter Future already retrieved exception will be raised. */ Future 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); - /** Fulfil this Promise (only for Promise) */ + /** Fulfill this Promise (only for Promise) */ void setValue(); /** Set the value (use perfect forwarding for both move and copy) */ template void setValue(M&& value); - void fulfilTry(Try t); + void setTry(Try 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 - void fulfil(F&& func); + void setWith(F&& func); private: typedef typename Future::corePtr corePtr; diff --git a/folly/futures/README.md b/folly/futures/README.md index 013e78c8..741fa234 100644 --- a/folly/futures/README.md +++ b/folly/futures/README.md @@ -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 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 p; -p.fulfil([]{ +p.setWith([]{ try { // do stuff that may throw return 42; diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index 4bdc5ef4..037ad138 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -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. diff --git a/folly/futures/test/Benchmark.cpp b/folly/futures/test/Benchmark.cpp index 053d4d9d..fbf2538f 100644 --- a/folly/futures/test/Benchmark.cpp +++ b/folly/futures/test/Benchmark.cpp @@ -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(); } diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index 01e63769..c74458ac 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -617,17 +617,17 @@ TEST(Promise, setException) { } } -TEST(Promise, fulfil) { +TEST(Promise, setWith) { { Promise p; auto f = p.getFuture(); - p.fulfil([] { return 42; }); + p.setWith([] { return 42; }); EXPECT_EQ(42, f.value()); } { Promise 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 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) { diff --git a/folly/futures/test/SugarTest.cpp b/folly/futures/test/SugarTest.cpp index bbafdebb..0563eef4 100644 --- a/folly/futures/test/SugarTest.cpp +++ b/folly/futures/test/SugarTest.cpp @@ -36,7 +36,7 @@ TEST(Sugar, pollNotReady) { TEST(Sugar, pollException) { Promise 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()); } diff --git a/folly/wangle/channel/OutputBufferingHandler.h b/folly/wangle/channel/OutputBufferingHandler.h index a1165ca1..e5ca99ae 100644 --- a/folly/wangle/channel/OutputBufferingHandler.h +++ b/folly/wangle/channel/OutputBufferingHandler.h @@ -58,7 +58,7 @@ class OutputBufferingHandler : public BytesToBytesHandler, MoveWrapper>> promises(std::move(promises_)); ctx_->fireWrite(std::move(sends_)).then([promises](Try t) mutable { for (auto& p : *promises) { - p.fulfilTry(t); + p.setTry(t); } }); } diff --git a/folly/wangle/concurrent/FutureExecutor.h b/folly/wangle/concurrent/FutureExecutor.h index e850f3a0..cbf4123a 100644 --- a/folly/wangle/concurrent/FutureExecutor.h +++ b/folly/wangle/concurrent/FutureExecutor.h @@ -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) 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; }