Short-Circuit within() When Future Is Already Complete
[folly.git] / folly / futures / FutureException.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <stdexcept>
20 #include <string>
21
22 namespace folly {
23
24 class FutureException : public std::logic_error {
25  public:
26   using std::logic_error::logic_error;
27 };
28
29 class BrokenPromise : public FutureException {
30  public:
31   explicit BrokenPromise(const std::string& type)
32       : FutureException("Broken promise for type name `" + type + '`') {}
33
34   explicit BrokenPromise(const char* type) : BrokenPromise(std::string(type)) {}
35 };
36
37 class NoState : public FutureException {
38  public:
39   NoState() : FutureException("No state") {}
40 };
41
42 [[noreturn]] void throwNoState();
43
44 class PromiseAlreadySatisfied : public FutureException {
45  public:
46   PromiseAlreadySatisfied() : FutureException("Promise already satisfied") {}
47 };
48
49 [[noreturn]] void throwPromiseAlreadySatisfied();
50
51 class FutureNotReady : public FutureException {
52  public:
53   FutureNotReady() : FutureException("Future not ready") {}
54 };
55
56 [[noreturn]] void throwFutureNotReady();
57
58 class FutureAlreadyRetrieved : public FutureException {
59  public:
60   FutureAlreadyRetrieved() : FutureException("Future already retrieved") {}
61 };
62
63 [[noreturn]] void throwFutureAlreadyRetrieved();
64
65 class FutureCancellation : public FutureException {
66  public:
67   FutureCancellation() : FutureException("Future was cancelled") {}
68 };
69
70 class TimedOut : public FutureException {
71  public:
72   TimedOut() : FutureException("Timed out") {}
73 };
74
75 [[noreturn]] void throwTimedOut();
76
77 class PredicateDoesNotObtain : public FutureException {
78  public:
79   PredicateDoesNotObtain() : FutureException("Predicate does not obtain") {}
80 };
81
82 [[noreturn]] void throwPredicateDoesNotObtain();
83
84 struct NoFutureInSplitter : FutureException {
85   NoFutureInSplitter() : FutureException("No Future in this FutureSplitter") {}
86 };
87
88 [[noreturn]] void throwNoFutureInSplitter();
89 }