Skip to content

Commit

Permalink
Perfect-forward the argument of Promise::setException
Browse files Browse the repository at this point in the history
Reviewed By: Orvid

Differential Revision: D48436733

fbshipit-source-id: 57dcd1d6910db6d1f05e56db938e884ab5c10e1d
  • Loading branch information
ot authored and facebook-github-bot committed Sep 3, 2023
1 parent 9e2c298 commit f513832
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions folly/futures/Promise-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ Future<T> Promise<T>::getFuture() {

template <class T>
template <class E>
typename std::enable_if<std::is_base_of<std::exception, E>::value>::type
Promise<T>::setException(E const& e) {
setException(make_exception_wrapper<E>(e));
typename std::enable_if<
std::is_base_of<std::exception, typename std::decay<E>::type>::value>::type
Promise<T>::setException(E&& e) {
setException(
make_exception_wrapper<typename std::decay<E>::type>(std::forward<E>(e)));
}

template <class T>
Expand Down
6 changes: 4 additions & 2 deletions folly/futures/Promise.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ class Promise {
///
/// Please see `setException(exception_wrapper)` for semantics/contract.
template <class E>
typename std::enable_if<std::is_base_of<std::exception, E>::value>::type
setException(E const& e);
typename std::enable_if<
std::is_base_of<std::exception, typename std::decay<E>::type>::value>::
type
setException(E&& e);

/// Sets a handler for the producer to receive a (logical) interruption
/// request (exception) sent from the consumer via `future.raise()`.
Expand Down

0 comments on commit f513832

Please sign in to comment.