From: James Sedgwick Date: Fri, 16 Jan 2015 14:33:13 +0000 (-0800) Subject: kill remaining Futures-related Wangle references X-Git-Tag: v0.23.0~44 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b407453624b13947a57035b1189eeef57fbffae2;p=folly.git 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 --- diff --git a/folly/Makefile.am b/folly/Makefile.am index c3b8ca9d..ce7f1e50 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -87,6 +87,7 @@ nobase_follyinclude_HEADERS = \ futures/Deprecated.h \ futures/Future-inl.h \ futures/Future.h \ + futures/FutureException.h \ futures/InlineExecutor.h \ futures/ManualExecutor.h \ futures/OpaqueCallbackShunt.h \ @@ -97,7 +98,6 @@ nobase_follyinclude_HEADERS = \ futures/Timekeeper.h \ futures/Try-inl.h \ futures/Try.h \ - futures/WangleException.h \ futures/detail/Core.h \ futures/detail/FSM.h \ futures/detail/ThreadWheelTimekeeper.h \ diff --git a/folly/futures/Future.h b/folly/futures/Future.h index 494bf6e1..cd3c36dc 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include namespace folly { @@ -108,8 +108,8 @@ namespace futures { /// Duration typedef of a `std::chrono` duration type indicates the /// resolution you can expect to be meaningful (milliseconds at the time of /// 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 - /// keep time for wangle timeouts) but we provide the option for power + /// use the global futures timekeeper (we run a thread whose job it is to + /// keep time for futures timeouts) but we provide the option for power /// users. /// /// The Timekeeper thread will be lazily created the first time it is diff --git a/folly/futures/FutureException.h b/folly/futures/FutureException.h new file mode 100644 index 00000000..7ce247c9 --- /dev/null +++ b/folly/futures/FutureException.h @@ -0,0 +1,94 @@ +/* + * Copyright 2014 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. + */ + +#pragma once + +#include +#include + +namespace folly { + +class FutureException : public std::exception { + +public: + + explicit FutureException(std::string message_arg) + : message(message_arg) {} + + ~FutureException() throw(){} + + virtual const char *what() const throw() { + return message.c_str(); + } + + bool operator==(const FutureException &other) const{ + return other.message == this->message; + } + + bool operator!=(const FutureException &other) const{ + return !(*this == other); + } + + protected: + std::string message; +}; + +class BrokenPromise : public FutureException { + public: + explicit BrokenPromise() : + FutureException("Broken promise") { } +}; + +class NoState : public FutureException { + public: + explicit NoState() : FutureException("No state") { } +}; + +class PromiseAlreadySatisfied : public FutureException { + public: + explicit PromiseAlreadySatisfied() : + FutureException("Promise already satisfied") { } +}; + +class FutureNotReady : public FutureException { + public: + explicit FutureNotReady() : + FutureException("Future not ready") { } +}; + +class FutureAlreadyRetrieved : public FutureException { + public: + explicit FutureAlreadyRetrieved () : + FutureException("Future already retrieved") { } +}; + +class UsingUninitializedTry : public FutureException { + public: + explicit UsingUninitializedTry() : + FutureException("Using unitialized try") { } +}; + +class FutureCancellation : public FutureException { + public: + FutureCancellation() : FutureException("Future was cancelled") {} +}; + +class TimedOut : public FutureException { + public: + TimedOut() : FutureException("Timed out") {} +}; + +} diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 044f94f1..94775a92 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -19,7 +19,7 @@ #include #include -#include +#include #include namespace folly { diff --git a/folly/futures/README.md b/folly/futures/README.md index 633b7438..39a1aa81 100644 --- a/folly/futures/README.md +++ b/folly/futures/README.md @@ -1,19 +1,8 @@ -# Wangle -Wangle is a framework for expressing asynchronous code in C++ using the Future pattern. +# folly::Futures -**wan•gle** |ˈwaNGgəl| informal -*verb* -Obtain (something that is desired) by persuading others to comply or by manipulating events. +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. -*noun* -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. +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. ## Brief Synopsis @@ -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. -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()) {} (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++ // Thread A @@ -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. -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. diff --git a/folly/futures/Try-inl.h b/folly/futures/Try-inl.h index 05cb4cce..612f5e9e 100644 --- a/folly/futures/Try-inl.h +++ b/folly/futures/Try-inl.h @@ -18,7 +18,7 @@ #include -#include +#include namespace folly { diff --git a/folly/futures/Try.h b/folly/futures/Try.h index 988bf2e8..7234a96e 100644 --- a/folly/futures/Try.h +++ b/folly/futures/Try.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace folly { @@ -178,7 +178,7 @@ class Try { exception_wrapper& exception() { if (UNLIKELY(!hasException())) { - throw WangleException("exception(): Try does not contain an exception"); + throw FutureException("exception(): Try does not contain an exception"); } return *e_; } @@ -274,13 +274,13 @@ class Try { } /* - * @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 */ exception_wrapper& exception() { if (UNLIKELY(!hasException())) { - throw WangleException("exception(): Try does not contain an exception"); + throw FutureException("exception(): Try does not contain an exception"); } return *e_; } diff --git a/folly/futures/WangleException.h b/folly/futures/WangleException.h deleted file mode 100644 index bfbbf39f..00000000 --- a/folly/futures/WangleException.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2014 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. - */ - -#pragma once - -#include -#include - -namespace folly { - -class WangleException : public std::exception { - -public: - - explicit WangleException(std::string message_arg) - : message(message_arg) {} - - ~WangleException() throw(){} - - virtual const char *what() const throw() { - return message.c_str(); - } - - bool operator==(const WangleException &other) const{ - return other.message == this->message; - } - - bool operator!=(const WangleException &other) const{ - return !(*this == other); - } - - protected: - std::string message; -}; - -class BrokenPromise : public WangleException { - public: - explicit BrokenPromise() : - WangleException("Broken promise") { } -}; - -class NoState : public WangleException { - public: - explicit NoState() : WangleException("No state") { } -}; - -class PromiseAlreadySatisfied : public WangleException { - public: - explicit PromiseAlreadySatisfied() : - WangleException("Promise already satisfied") { } -}; - -class FutureNotReady : public WangleException { - public: - explicit FutureNotReady() : - WangleException("Future not ready") { } -}; - -class FutureAlreadyRetrieved : public WangleException { - public: - explicit FutureAlreadyRetrieved () : - WangleException("Future already retrieved") { } -}; - -class UsingUninitializedTry : public WangleException { - public: - explicit UsingUninitializedTry() : - WangleException("Using unitialized try") { } -}; - -class FutureCancellation : public WangleException { - public: - FutureCancellation() : WangleException("Future was cancelled") {} -}; - -class TimedOut : public WangleException { - public: - TimedOut() : WangleException("Timed out") {} -}; - -} diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index cbb94472..4fa1c274 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -77,7 +77,7 @@ class ThreadExecutor : public Executor { } }; -typedef WangleException eggs_t; +typedef FutureException eggs_t; static eggs_t eggs("eggs"); // Future