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 = \
FingerprintTables.cpp \
futures/Barrier.cpp \
futures/Future.cpp \
futures/FutureException.cpp \
futures/ManualExecutor.cpp \
futures/QueuedImmediateExecutor.cpp \
futures/ThreadWheelTimekeeper.cpp \
......
......@@ -217,7 +217,7 @@ void Future<T>::detach() {
template <class T>
void Future<T>::throwIfInvalid() const {
if (!core_)
throw NoState();
throwNoState();
}
template <class T>
......@@ -1202,7 +1202,7 @@ T Future<T>::get(Duration dur) {
if (isReady()) {
return std::move(value());
} else {
throw TimedOut();
throwTimedOut();
}
}
......@@ -1240,7 +1240,7 @@ Future<T> Future<T>::filter(F&& predicate) {
return this->then([p = std::forward<F>(predicate)](T val) {
T const& valConstRef = val;
if (!p(valConstRef)) {
throw PredicateDoesNotObtain();
throwPredicateDoesNotObtain();
}
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 {
NoState() : FutureException("No state") {}
};
[[noreturn]] void throwNoState();
class PromiseAlreadySatisfied : public FutureException {
public:
PromiseAlreadySatisfied() : FutureException("Promise already satisfied") {}
};
[[noreturn]] void throwPromiseAlreadySatisfied();
class FutureNotReady : public FutureException {
public:
FutureNotReady() : FutureException("Future not ready") {}
};
[[noreturn]] void throwFutureNotReady();
class FutureAlreadyRetrieved : public FutureException {
public:
FutureAlreadyRetrieved() : FutureException("Future already retrieved") {}
};
[[noreturn]] void throwFutureAlreadyRetrieved();
class FutureCancellation : public FutureException {
public:
FutureCancellation() : FutureException("Future was cancelled") {}
......@@ -64,12 +72,18 @@ class TimedOut : public FutureException {
TimedOut() : FutureException("Timed out") {}
};
[[noreturn]] void throwTimedOut();
class PredicateDoesNotObtain : public FutureException {
public:
PredicateDoesNotObtain() : FutureException("Predicate does not obtain") {}
};
[[noreturn]] void throwPredicateDoesNotObtain();
struct NoFutureInSplitter : FutureException {
NoFutureInSplitter() : FutureException("No Future in this FutureSplitter") {}
};
[[noreturn]] void throwNoFutureInSplitter();
}
......@@ -55,8 +55,8 @@ class FutureSplitter {
* This can be called an unlimited number of times per FutureSplitter.
*/
Future<T> getFuture() {
if (UNLIKELY(promise_ == nullptr)) {
throw NoFutureInSplitter();
if (promise_ == nullptr) {
throwNoFutureInSplitter();
}
return promise_->getFuture();
}
......
......@@ -49,18 +49,18 @@ Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
template <class T>
void Promise<T>::throwIfFulfilled() {
if (UNLIKELY(!core_)) {
throw NoState();
if (!core_) {
throwNoState();
}
if (UNLIKELY(core_->ready())) {
throw PromiseAlreadySatisfied();
if (core_->ready()) {
throwPromiseAlreadySatisfied();
}
}
template <class T>
void Promise<T>::throwIfRetrieved() {
if (UNLIKELY(retrieved_)) {
throw FutureAlreadyRetrieved();
if (retrieved_) {
throwFutureAlreadyRetrieved();
}
}
......
......@@ -16,11 +16,13 @@
#pragma once
#include <folly/Executor.h>
#include <chrono>
#include <memory>
#include <stdexcept>
#include <folly/Executor.h>
#include <folly/portability/BitsFunctexcept.h>
namespace folly {
// An executor that supports timed scheduling. Like RxScheduler.
class ScheduledExecutor : public virtual Executor {
......@@ -46,7 +48,7 @@ namespace folly {
/// Schedule a Func to be executed at time t, or as soon afterward as
/// possible. Expect millisecond resolution at best. Must be threadsafe.
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.
......
......@@ -117,7 +117,7 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
{
std::lock_guard<std::mutex> g(mutex_);
if (hasValue_) {
throw PromiseAlreadySatisfied();
throwPromiseAlreadySatisfied();
}
hasValue_ = true;
try_ = std::move(t);
......
......@@ -31,6 +31,7 @@
#include <folly/Utility.h>
#include <folly/futures/FutureException.h>
#include <folly/futures/detail/FSM.h>
#include <folly/portability/BitsFunctexcept.h>
#include <folly/io/async/Request.h>
......@@ -134,7 +135,7 @@ class Core final {
if (ready()) {
return *result_;
} else {
throw FutureNotReady();
throwFutureNotReady();
}
}
......@@ -160,7 +161,7 @@ class Core final {
case State::OnlyCallback:
case State::Armed:
case State::Done:
throw std::logic_error("setCallback called twice");
std::__throw_logic_error("setCallback called twice");
FSM_END
// we could always call this, it is an optimization to only call it when
......@@ -187,7 +188,7 @@ class Core final {
case State::OnlyResult:
case State::Armed:
case State::Done:
throw std::logic_error("setResult called twice");
std::__throw_logic_error("setResult called twice");
FSM_END
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