mirror of
https://github.com/clearlinux/folly.git
synced 2026-09-01 11:15:52 +00:00
Promise::setValue() for Unit
Summary: Unit is a bit special because it's just something special to use instead of `Promise<void>`, so let's offer the same sugar that `Promise<void>` has (`p.setValue()` instead of `p.setValue(Unit())`) Test Plan: New unit tests. Look, a pun! Reviewed By: jsedgwick@fb.com Subscribers: exa, folly-diffs@, jsedgwick, yfeldblum, chalfant, davejwatson, hannesr FB internal diff: D2014139 Tasks: 6847876 Signature: t1:2014139:1430159950:1484ee420c6d7f0f794a546b78ef1601c2eec45c
This commit is contained in:
committed by
Andrii Grynenko
parent
0cfa7e4b56
commit
ef0137ceaf
@@ -123,14 +123,6 @@ void Promise<T>::setValue(M&& v) {
|
||||
setTry(Try<T>(std::forward<M>(v)));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Promise<T>::setValue() {
|
||||
static_assert(std::is_same<T, void>::value,
|
||||
"Use setValue(value) instead");
|
||||
|
||||
setTry(Try<void>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
template <class F>
|
||||
void Promise<T>::setWith(F&& func) {
|
||||
|
||||
+13
-2
@@ -70,8 +70,19 @@ public:
|
||||
/// handled.
|
||||
void setInterruptHandler(std::function<void(exception_wrapper const&)>);
|
||||
|
||||
/** Fulfill this Promise (only for Promise<void>) */
|
||||
void setValue();
|
||||
/// Fulfill this Promise<void>
|
||||
template <class B = T>
|
||||
typename std::enable_if<std::is_void<B>::value, void>::type
|
||||
setValue() {
|
||||
setTry(Try<T>());
|
||||
}
|
||||
|
||||
/// Sugar to fulfill this Promise<Unit>
|
||||
template <class B = T>
|
||||
typename std::enable_if<std::is_same<Unit, B>::value, void>::type
|
||||
setValue() {
|
||||
setTry(Try<T>(T()));
|
||||
}
|
||||
|
||||
/** Set the value (use perfect forwarding for both move and copy) */
|
||||
template <class M>
|
||||
|
||||
@@ -1779,3 +1779,8 @@ TEST(Map, Basic) {
|
||||
|
||||
EXPECT_TRUE(collect(fs2).isReady());
|
||||
}
|
||||
|
||||
TEST(Promise, defaultConstructedUnit) {
|
||||
Promise<Unit> p;
|
||||
p.setValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user