Commit 063b4a3d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Outline throw statements in folly/futures/

Summary: [Folly] Outline `throw` statements in `folly/futures/`.

Reviewed By: ericniebler

Differential Revision: D5522791

fbshipit-source-id: 545185bc580ea8628075b9ecae46c2f19308e937
parent 9ab15578
...@@ -474,6 +474,7 @@ libfolly_la_SOURCES = \ ...@@ -474,6 +474,7 @@ libfolly_la_SOURCES = \
FingerprintTables.cpp \ FingerprintTables.cpp \
futures/Barrier.cpp \ futures/Barrier.cpp \
futures/Future.cpp \ futures/Future.cpp \
futures/FutureException.cpp \
futures/ManualExecutor.cpp \ futures/ManualExecutor.cpp \
futures/QueuedImmediateExecutor.cpp \ futures/QueuedImmediateExecutor.cpp \
futures/ThreadWheelTimekeeper.cpp \ futures/ThreadWheelTimekeeper.cpp \
......
...@@ -217,7 +217,7 @@ void Future<T>::detach() { ...@@ -217,7 +217,7 @@ void Future<T>::detach() {
template <class T> template <class T>
void Future<T>::throwIfInvalid() const { void Future<T>::throwIfInvalid() const {
if (!core_) if (!core_)
throw NoState(); throwNoState();
} }
template <class T> template <class T>
...@@ -1202,7 +1202,7 @@ T Future<T>::get(Duration dur) { ...@@ -1202,7 +1202,7 @@ T Future<T>::get(Duration dur) {
if (isReady()) { if (isReady()) {
return std::move(value()); return std::move(value());
} else { } else {
throw TimedOut(); throwTimedOut();
} }
} }
...@@ -1240,7 +1240,7 @@ Future<T> Future<T>::filter(F&& predicate) { ...@@ -1240,7 +1240,7 @@ Future<T> Future<T>::filter(F&& predicate) {
return this->then([p = std::forward<F>(predicate)](T val) { return this->then([p = std::forward<F>(predicate)](T val) {
T const& valConstRef = val; T const& valConstRef = val;
if (!p(valConstRef)) { if (!p(valConstRef)) {
throw PredicateDoesNotObtain(); throwPredicateDoesNotObtain();
} }
return val; return val;
}); });
......
/*
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/futures/FutureException.h>
namespace folly {
[[noreturn]] void throwNoState() {
throw NoState();
}
[[noreturn]] void throwPromiseAlreadySatisfied() {
throw PromiseAlreadySatisfied();
}
[[noreturn]] void throwFutureNotReady() {
throw FutureNotReady();
}
[[noreturn]] void throwFutureAlreadyRetrieved() {
throw FutureAlreadyRetrieved();
}
[[noreturn]] void throwTimedOut() {
throw TimedOut();
}
[[noreturn]] void throwPredicateDoesNotObtain() {
throw PredicateDoesNotObtain();
}
[[noreturn]] void throwNoFutureInSplitter() {
throw NoFutureInSplitter();
}
}
...@@ -39,21 +39,29 @@ class NoState : public FutureException { ...@@ -39,21 +39,29 @@ class NoState : public FutureException {
NoState() : FutureException("No state") {} NoState() : FutureException("No state") {}
}; };
[[noreturn]] void throwNoState();
class PromiseAlreadySatisfied : public FutureException { class PromiseAlreadySatisfied : public FutureException {
public: public:
PromiseAlreadySatisfied() : FutureException("Promise already satisfied") {} PromiseAlreadySatisfied() : FutureException("Promise already satisfied") {}
}; };
[[noreturn]] void throwPromiseAlreadySatisfied();
class FutureNotReady : public FutureException { class FutureNotReady : public FutureException {
public: public:
FutureNotReady() : FutureException("Future not ready") {} FutureNotReady() : FutureException("Future not ready") {}
}; };
[[noreturn]] void throwFutureNotReady();
class FutureAlreadyRetrieved : public FutureException { class FutureAlreadyRetrieved : public FutureException {
public: public:
FutureAlreadyRetrieved() : FutureException("Future already retrieved") {} FutureAlreadyRetrieved() : FutureException("Future already retrieved") {}
}; };
[[noreturn]] void throwFutureAlreadyRetrieved();
class FutureCancellation : public FutureException { class FutureCancellation : public FutureException {
public: public:
FutureCancellation() : FutureException("Future was cancelled") {} FutureCancellation() : FutureException("Future was cancelled") {}
...@@ -64,12 +72,18 @@ class TimedOut : public FutureException { ...@@ -64,12 +72,18 @@ class TimedOut : public FutureException {
TimedOut() : FutureException("Timed out") {} TimedOut() : FutureException("Timed out") {}
}; };
[[noreturn]] void throwTimedOut();
class PredicateDoesNotObtain : public FutureException { class PredicateDoesNotObtain : public FutureException {
public: public:
PredicateDoesNotObtain() : FutureException("Predicate does not obtain") {} PredicateDoesNotObtain() : FutureException("Predicate does not obtain") {}
}; };
[[noreturn]] void throwPredicateDoesNotObtain();
struct NoFutureInSplitter : FutureException { struct NoFutureInSplitter : FutureException {
NoFutureInSplitter() : FutureException("No Future in this FutureSplitter") {} NoFutureInSplitter() : FutureException("No Future in this FutureSplitter") {}
}; };
[[noreturn]] void throwNoFutureInSplitter();
} }
...@@ -55,8 +55,8 @@ class FutureSplitter { ...@@ -55,8 +55,8 @@ class FutureSplitter {
* This can be called an unlimited number of times per FutureSplitter. * This can be called an unlimited number of times per FutureSplitter.
*/ */
Future<T> getFuture() { Future<T> getFuture() {
if (UNLIKELY(promise_ == nullptr)) { if (promise_ == nullptr) {
throw NoFutureInSplitter(); throwNoFutureInSplitter();
} }
return promise_->getFuture(); return promise_->getFuture();
} }
......
...@@ -49,18 +49,18 @@ Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept { ...@@ -49,18 +49,18 @@ Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
template <class T> template <class T>
void Promise<T>::throwIfFulfilled() { void Promise<T>::throwIfFulfilled() {
if (UNLIKELY(!core_)) { if (!core_) {
throw NoState(); throwNoState();
} }
if (UNLIKELY(core_->ready())) { if (core_->ready()) {
throw PromiseAlreadySatisfied(); throwPromiseAlreadySatisfied();
} }
} }
template <class T> template <class T>
void Promise<T>::throwIfRetrieved() { void Promise<T>::throwIfRetrieved() {
if (UNLIKELY(retrieved_)) { if (retrieved_) {
throw FutureAlreadyRetrieved(); throwFutureAlreadyRetrieved();
} }
} }
......
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
#pragma once #pragma once
#include <folly/Executor.h>
#include <chrono> #include <chrono>
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
#include <folly/Executor.h>
#include <folly/portability/BitsFunctexcept.h>
namespace folly { namespace folly {
// An executor that supports timed scheduling. Like RxScheduler. // An executor that supports timed scheduling. Like RxScheduler.
class ScheduledExecutor : public virtual Executor { class ScheduledExecutor : public virtual Executor {
...@@ -46,7 +48,7 @@ namespace folly { ...@@ -46,7 +48,7 @@ namespace folly {
/// Schedule a Func to be executed at time t, or as soon afterward as /// Schedule a Func to be executed at time t, or as soon afterward as
/// possible. Expect millisecond resolution at best. Must be threadsafe. /// possible. Expect millisecond resolution at best. Must be threadsafe.
virtual void scheduleAt(Func&& /* a */, TimePoint const& /* t */) { virtual void scheduleAt(Func&& /* a */, TimePoint const& /* t */) {
throw std::logic_error("unimplemented"); std::__throw_logic_error("unimplemented");
} }
/// Get this executor's notion of time. Must be threadsafe. /// Get this executor's notion of time. Must be threadsafe.
......
...@@ -117,7 +117,7 @@ void SharedPromise<T>::setTry(Try<T>&& t) { ...@@ -117,7 +117,7 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
{ {
std::lock_guard<std::mutex> g(mutex_); std::lock_guard<std::mutex> g(mutex_);
if (hasValue_) { if (hasValue_) {
throw PromiseAlreadySatisfied(); throwPromiseAlreadySatisfied();
} }
hasValue_ = true; hasValue_ = true;
try_ = std::move(t); try_ = std::move(t);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <folly/Utility.h> #include <folly/Utility.h>
#include <folly/futures/FutureException.h> #include <folly/futures/FutureException.h>
#include <folly/futures/detail/FSM.h> #include <folly/futures/detail/FSM.h>
#include <folly/portability/BitsFunctexcept.h>
#include <folly/io/async/Request.h> #include <folly/io/async/Request.h>
...@@ -134,7 +135,7 @@ class Core final { ...@@ -134,7 +135,7 @@ class Core final {
if (ready()) { if (ready()) {
return *result_; return *result_;
} else { } else {
throw FutureNotReady(); throwFutureNotReady();
} }
} }
...@@ -160,7 +161,7 @@ class Core final { ...@@ -160,7 +161,7 @@ class Core final {
case State::OnlyCallback: case State::OnlyCallback:
case State::Armed: case State::Armed:
case State::Done: case State::Done:
throw std::logic_error("setCallback called twice"); std::__throw_logic_error("setCallback called twice");
FSM_END FSM_END
// we could always call this, it is an optimization to only call it when // we could always call this, it is an optimization to only call it when
...@@ -187,7 +188,7 @@ class Core final { ...@@ -187,7 +188,7 @@ class Core final {
case State::OnlyResult: case State::OnlyResult:
case State::Armed: case State::Armed:
case State::Done: case State::Done:
throw std::logic_error("setResult called twice"); std::__throw_logic_error("setResult called twice");
FSM_END FSM_END
if (transitionToArmed) { if (transitionToArmed) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment