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);
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>
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)));
}
}}
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) */
*
* @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));
if (!isTry && t.hasException()) {
p->setException(std::move(t.exception()));
} else {
- p->fulfil([&]() {
+ p->setWith([&]() {
return (*funcm)(t.template get<isTry, 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));
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));
}
});
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));
pm->setException(exception_wrapper(std::current_exception()));
}
})) {
- pm->fulfilTry(std::move(t));
+ pm->setTry(std::move(t));
}
});
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);
}
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)();
});
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();
}
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;
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)));
}
}
});
this->then([ctx](Try<T>&& t) {
if (ctx->token.exchange(true) == false) {
- ctx->promise.fulfilTry(std::move(t));
+ ctx->promise.setTry(std::move(t));
}
});
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);
};
}
}
template <class T>
-void Promise<T>::fulfilTry(Try<T> t) {
+void Promise<T>::setTry(Try<T> t) {
throwIfFulfilled();
core_->setResult(std::move(t));
}
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>
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)));
}
}
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 (...) {
*/
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.
*/
/// 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;
## 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;
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;
/// 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.
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()
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();
}
}
}
-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);
}
}
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);
}
EXPECT_EQ(nullptr, RequestContext::get()->getContextData("test"));
- // Fulfil the promise
+ // Fulfill the promise
p.setValue();
}
ptr.reset();
- promise.fulfil([]{return 1l;});
+ promise.setWith([]{return 1l;});
}
TEST(Future, Constructor) {
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());
}
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);
}
});
}
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;
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;
}