Commit b4074536 authored by James Sedgwick's avatar James Sedgwick Committed by woo

kill remaining Futures-related Wangle references

Summary: grep around for wangle, adjust where appropriate

Test Plan: contbuild

Reviewed By: hans@fb.com

Subscribers: trunkagent, fbcode-common-diffs@, ruibalp, zeus-diffs@, vikas, targeting-diff-backend@, alandau, mwa, jgehring, zhguo, jying, darshan, fuegen, mshneer, folly-diffs@, lins, maxwellsayles, jsedgwick

FB internal diff: D1777581

Tasks: 5960242

Signature: t1:1777581:1421361395:2ee8bfeca76dafe7376a217c66e0a4eaf3ef416a
parent 1509cebb
...@@ -87,6 +87,7 @@ nobase_follyinclude_HEADERS = \ ...@@ -87,6 +87,7 @@ nobase_follyinclude_HEADERS = \
futures/Deprecated.h \ futures/Deprecated.h \
futures/Future-inl.h \ futures/Future-inl.h \
futures/Future.h \ futures/Future.h \
futures/FutureException.h \
futures/InlineExecutor.h \ futures/InlineExecutor.h \
futures/ManualExecutor.h \ futures/ManualExecutor.h \
futures/OpaqueCallbackShunt.h \ futures/OpaqueCallbackShunt.h \
...@@ -97,7 +98,6 @@ nobase_follyinclude_HEADERS = \ ...@@ -97,7 +98,6 @@ nobase_follyinclude_HEADERS = \
futures/Timekeeper.h \ futures/Timekeeper.h \
futures/Try-inl.h \ futures/Try-inl.h \
futures/Try.h \ futures/Try.h \
futures/WangleException.h \
futures/detail/Core.h \ futures/detail/Core.h \
futures/detail/FSM.h \ futures/detail/FSM.h \
futures/detail/ThreadWheelTimekeeper.h \ futures/detail/ThreadWheelTimekeeper.h \
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <folly/futures/Deprecated.h> #include <folly/futures/Deprecated.h>
#include <folly/futures/Promise.h> #include <folly/futures/Promise.h>
#include <folly/futures/Try.h> #include <folly/futures/Try.h>
#include <folly/futures/WangleException.h> #include <folly/futures/FutureException.h>
#include <folly/futures/detail/Types.h> #include <folly/futures/detail/Types.h>
namespace folly { namespace folly {
...@@ -108,8 +108,8 @@ namespace futures { ...@@ -108,8 +108,8 @@ namespace futures {
/// Duration typedef of a `std::chrono` duration type indicates the /// Duration typedef of a `std::chrono` duration type indicates the
/// resolution you can expect to be meaningful (milliseconds at the time of /// resolution you can expect to be meaningful (milliseconds at the time of
/// writing). Normally you wouldn't need to specify a Timekeeper, we will /// writing). Normally you wouldn't need to specify a Timekeeper, we will
/// use the global wangle timekeeper (we run a thread whose job it is to /// use the global futures timekeeper (we run a thread whose job it is to
/// keep time for wangle timeouts) but we provide the option for power /// keep time for futures timeouts) but we provide the option for power
/// users. /// users.
/// ///
/// The Timekeeper thread will be lazily created the first time it is /// The Timekeeper thread will be lazily created the first time it is
......
...@@ -21,24 +21,24 @@ ...@@ -21,24 +21,24 @@
namespace folly { namespace folly {
class WangleException : public std::exception { class FutureException : public std::exception {
public: public:
explicit WangleException(std::string message_arg) explicit FutureException(std::string message_arg)
: message(message_arg) {} : message(message_arg) {}
~WangleException() throw(){} ~FutureException() throw(){}
virtual const char *what() const throw() { virtual const char *what() const throw() {
return message.c_str(); return message.c_str();
} }
bool operator==(const WangleException &other) const{ bool operator==(const FutureException &other) const{
return other.message == this->message; return other.message == this->message;
} }
bool operator!=(const WangleException &other) const{ bool operator!=(const FutureException &other) const{
return !(*this == other); return !(*this == other);
} }
...@@ -46,49 +46,49 @@ public: ...@@ -46,49 +46,49 @@ public:
std::string message; std::string message;
}; };
class BrokenPromise : public WangleException { class BrokenPromise : public FutureException {
public: public:
explicit BrokenPromise() : explicit BrokenPromise() :
WangleException("Broken promise") { } FutureException("Broken promise") { }
}; };
class NoState : public WangleException { class NoState : public FutureException {
public: public:
explicit NoState() : WangleException("No state") { } explicit NoState() : FutureException("No state") { }
}; };
class PromiseAlreadySatisfied : public WangleException { class PromiseAlreadySatisfied : public FutureException {
public: public:
explicit PromiseAlreadySatisfied() : explicit PromiseAlreadySatisfied() :
WangleException("Promise already satisfied") { } FutureException("Promise already satisfied") { }
}; };
class FutureNotReady : public WangleException { class FutureNotReady : public FutureException {
public: public:
explicit FutureNotReady() : explicit FutureNotReady() :
WangleException("Future not ready") { } FutureException("Future not ready") { }
}; };
class FutureAlreadyRetrieved : public WangleException { class FutureAlreadyRetrieved : public FutureException {
public: public:
explicit FutureAlreadyRetrieved () : explicit FutureAlreadyRetrieved () :
WangleException("Future already retrieved") { } FutureException("Future already retrieved") { }
}; };
class UsingUninitializedTry : public WangleException { class UsingUninitializedTry : public FutureException {
public: public:
explicit UsingUninitializedTry() : explicit UsingUninitializedTry() :
WangleException("Using unitialized try") { } FutureException("Using unitialized try") { }
}; };
class FutureCancellation : public WangleException { class FutureCancellation : public FutureException {
public: public:
FutureCancellation() : WangleException("Future was cancelled") {} FutureCancellation() : FutureException("Future was cancelled") {}
}; };
class TimedOut : public WangleException { class TimedOut : public FutureException {
public: public:
TimedOut() : WangleException("Timed out") {} TimedOut() : FutureException("Timed out") {}
}; };
} }
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <atomic> #include <atomic>
#include <thread> #include <thread>
#include <folly/futures/WangleException.h> #include <folly/futures/FutureException.h>
#include <folly/futures/detail/Core.h> #include <folly/futures/detail/Core.h>
namespace folly { namespace folly {
......
# Wangle # folly::Futures
Wangle is a framework for expressing asynchronous code in C++ using the Future pattern.
**wan•gle** |ˈwaNGgəl| informal Futures is a futures-based async framework inspired by [Twitter's Finagle](http://twitter.github.io/finagle/) (which is in scala), and (loosely) building upon the existing (but anemic) Futures code found in the C++11 standard ([`std::future`](http://en.cppreference.com/w/cpp/thread/future)) and [`boost::future`](http://www.boost.org/doc/libs/1_53_0/boost/thread/future.hpp) (especially >= 1.53.0). Although inspired by the std::future interface, it is not syntactically drop-in compatible because some ideas didn't translate well enough and we decided to break from the API. But semantically, it should be straightforward to translate from existing std::future code to Futures.
*verb*
Obtain (something that is desired) by persuading others to comply or by manipulating events.
*noun* The primary semantic differences are that folly's Futures and Promises are not threadsafe; and as does `boost::future`, folly::Futures support continuing callbacks (`then()`) and there are helper methods `whenAll()` and `whenAny()` which are important compositional building blocks.
A framework for expressing asynchronous control flow in C++, that is composable and easily translated to/from synchronous code.
*synonyms*
[Finagle](http://twitter.github.io/finagle/)
Wangle is a futures-based async framework inspired by [Twitter's Finagle](http://twitter.github.io/finagle/) (which is in scala), and (loosely) building upon the existing (but anemic) Futures code found in the C++11 standard ([`std::future`](http://en.cppreference.com/w/cpp/thread/future)) and [`boost::future`](http://www.boost.org/doc/libs/1_53_0/boost/thread/future.hpp) (especially >= 1.53.0). Although inspired by the std::future interface, it is not syntactically drop-in compatible because some ideas didn't translate well enough and we decided to break from the API. But semantically, it should be straightforward to translate from existing std::future code to Wangle.
The primary semantic differences are that Wangle Futures and Promises are not threadsafe; and as does `boost::future`, Wangle supports continuing callbacks (`then()`) and there are helper methods `whenAll()` and `whenAny()` which are important compositional building blocks.
## Brief Synopsis ## Brief Synopsis
...@@ -167,13 +156,13 @@ Using `then` to add callbacks is idiomatic. It brings all the code into one plac ...@@ -167,13 +156,13 @@ Using `then` to add callbacks is idiomatic. It brings all the code into one plac
Up to this point we have skirted around the matter of waiting for Futures. You may never need to wait for a Future, because your code is event-driven and all follow-up action happens in a then-block. But if want to have a batch workflow, where you initiate a batch of asynchronous operations and then wait for them all to finish at a synchronization point, then you will want to wait for a Future. Up to this point we have skirted around the matter of waiting for Futures. You may never need to wait for a Future, because your code is event-driven and all follow-up action happens in a then-block. But if want to have a batch workflow, where you initiate a batch of asynchronous operations and then wait for them all to finish at a synchronization point, then you will want to wait for a Future.
Other future frameworks like Finagle and std::future/boost::future, give you the ability to wait directly on a Future, by calling `fut.wait()` (naturally enough). Wangle has diverged from this pattern because we don't want to be in the business of dictating how your thread waits. We may work out something that we feel is sufficiently general, in the meantime adapt this spin loop to however your thread should wait: Other future frameworks like Finagle and std::future/boost::future, give you the ability to wait directly on a Future, by calling `fut.wait()` (naturally enough). Futures have diverged from this pattern because we don't want to be in the business of dictating how your thread waits. We may work out something that we feel is sufficiently general, in the meantime adapt this spin loop to however your thread should wait:
while (!f.isReady()) {} while (!f.isReady()) {}
(Hint: you might want to use an event loop or a semaphore or something. You probably don't want to just spin like this.) (Hint: you might want to use an event loop or a semaphore or something. You probably don't want to just spin like this.)
Wangle is partially threadsafe. A Promise or Future can migrate between threads as long as there's a full memory barrier of some sort. `Future::then` and `Promise::setValue` (and all variants that boil down to those two calls) can be called from different threads. BUT, be warned that you might be surprised about which thread your callback executes on. Let's consider an example. Futures are partially threadsafe. A Promise or Future can migrate between threads as long as there's a full memory barrier of some sort. `Future::then` and `Promise::setValue` (and all variants that boil down to those two calls) can be called from different threads. BUT, be warned that you might be surprised about which thread your callback executes on. Let's consider an example.
```C++ ```C++
// Thread A // Thread A
...@@ -275,4 +264,4 @@ C++ doesn't directly support continuations very well. But there are some ways to ...@@ -275,4 +264,4 @@ C++ doesn't directly support continuations very well. But there are some ways to
The tradeoff is memory. Each continuation has a stack, and that stack is usually fixed-size and has to be big enough to support whatever ordinary computation you might want to do on it. So each living continuation requires a relatively large amount of memory. If you know the number of continuations will be small, this might be a good fit. In particular, it might be faster and the code might read cleaner. The tradeoff is memory. Each continuation has a stack, and that stack is usually fixed-size and has to be big enough to support whatever ordinary computation you might want to do on it. So each living continuation requires a relatively large amount of memory. If you know the number of continuations will be small, this might be a good fit. In particular, it might be faster and the code might read cleaner.
Wangle takes the middle road between callback hell and continuations, one which has been trodden and proved useful in other languages. It doesn't claim to be the best model for all situations. Use your tools wisely. Futures takes the middle road between callback hell and continuations, one which has been trodden and proved useful in other languages. It doesn't claim to be the best model for all situations. Use your tools wisely.
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <stdexcept> #include <stdexcept>
#include <folly/futures/WangleException.h> #include <folly/futures/FutureException.h>
namespace folly { namespace folly {
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <folly/Likely.h> #include <folly/Likely.h>
#include <folly/Memory.h> #include <folly/Memory.h>
#include <folly/futures/Deprecated.h> #include <folly/futures/Deprecated.h>
#include <folly/futures/WangleException.h> #include <folly/futures/FutureException.h>
namespace folly { namespace folly {
...@@ -178,7 +178,7 @@ class Try { ...@@ -178,7 +178,7 @@ class Try {
exception_wrapper& exception() { exception_wrapper& exception() {
if (UNLIKELY(!hasException())) { if (UNLIKELY(!hasException())) {
throw WangleException("exception(): Try does not contain an exception"); throw FutureException("exception(): Try does not contain an exception");
} }
return *e_; return *e_;
} }
...@@ -274,13 +274,13 @@ class Try<void> { ...@@ -274,13 +274,13 @@ class Try<void> {
} }
/* /*
* @throws WangleException if the Try doesn't contain an exception * @throws FutureException if the Try doesn't contain an exception
* *
* @returns mutable reference to the exception contained by this Try * @returns mutable reference to the exception contained by this Try
*/ */
exception_wrapper& exception() { exception_wrapper& exception() {
if (UNLIKELY(!hasException())) { if (UNLIKELY(!hasException())) {
throw WangleException("exception(): Try does not contain an exception"); throw FutureException("exception(): Try does not contain an exception");
} }
return *e_; return *e_;
} }
......
...@@ -77,7 +77,7 @@ class ThreadExecutor : public Executor { ...@@ -77,7 +77,7 @@ class ThreadExecutor : public Executor {
} }
}; };
typedef WangleException eggs_t; typedef FutureException eggs_t;
static eggs_t eggs("eggs"); static eggs_t eggs("eggs");
// Future // Future
......
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