From: Hans Fugal Date: Fri, 21 Feb 2014 18:52:22 +0000 (-0800) Subject: (wangle) comment cleanup X-Git-Tag: v0.22.0~671 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=07b986bf1b17b7965382862aef3197d44ec98068;p=folly.git (wangle) comment cleanup Summary: Cleaning up some inaccuracies, adding just a little detail in a few places, and trying very hard not to get OCD about the commenting style. Test Plan: still builds Reviewed By: hannesr@fb.com FB internal diff: D1184910 --- diff --git a/folly/wangle/Future-inl.h b/folly/wangle/Future-inl.h index c1da48fe..46a63d52 100644 --- a/folly/wangle/Future-inl.h +++ b/folly/wangle/Future-inl.h @@ -400,3 +400,8 @@ whenN(InputIterator first, InputIterator last, size_t n) { } }} + +// I haven't included a Future specialization because I don't forsee us +// using it, however it is not difficult to add when needed. Refer to +// Future for guidance. std::future and boost::future code would also be +// instructive. diff --git a/folly/wangle/Future.h b/folly/wangle/Future.h index 39b3c0a8..3b3bcf06 100644 --- a/folly/wangle/Future.h +++ b/folly/wangle/Future.h @@ -75,8 +75,7 @@ class Future { template void executeWith(Executor* executor, Promise&& cont_promise); - /** True when the result (or exception) is ready. value() will not block - when this returns true. */ + /** True when the result (or exception) is ready. */ bool isReady() const; /** A reference to the Try of the value */ @@ -88,36 +87,39 @@ class Future { Future f2 = f1.then([](Try&&) { return string("foo"); }); - The functor given may call value() without blocking, which may rethrow if - this has captured an exception. If func throws, the exception will be - captured in the Future that is returned. + The Future given to the functor is ready, and the functor may call + value(), which may rethrow if this has captured an exception. If func + throws, the exception will be captured in the Future that is returned. */ - /* n3428 has then(scheduler&, F&&), we might want to reorganize to use - similar API. or maybe not */ + /* TODO n3428 and other async frameworks have something like then(scheduler, + Future), we probably want to support a similar API (instead of + executeWith). */ template typename std::enable_if< !isFuture&&)>::type>::value, Future&&)>::type> >::type then(F&& func); + /// Variant where func returns a future instead of a T. e.g. + /// + /// Future f2 = f1.then( + /// [](Try&&) { return makeFuture("foo"); }); template typename std::enable_if< isFuture&&)>::type>::value, Future&&)>::type::value_type> >::type then(F&& func); - /** Use this method on the Future when we don't really care about the - returned value and want to convert the Future to a Future - Convenience function - */ + /// Convenience method for ignoring the value and creating a Future. + /// Exceptions still propagate. Future then(); + /// Use of this method is advanced wizardry. + /// XXX should this be protected? template void setContinuation(F&& func); private: - /* Eventually this may not be a shared_ptr, but something similar without - expensive thread-safety. */ typedef detail::FutureObject* objPtr; // shared state object @@ -131,8 +133,15 @@ class Future { friend class Promise; }; -/** Make a completed Future by moving in a value. e.g. - auto f = makeFuture(string("foo")); +/** + Make a completed Future by moving in a value. e.g. + + string foo = "foo"; + auto f = makeFuture(std::move(foo)); + + or + + auto f = makeFuture("foo"); */ template Future::type> makeFuture(T&& t); @@ -154,11 +163,10 @@ auto makeFutureTry( F const& func) -> Future; -/** Make a completed (error) Future from an exception_ptr. Because the type -can't be inferred you have to give it, e.g. - -auto f = makeFuture(std::current_exception()); -*/ +/// Make a failed Future from an exception_ptr. +/// Because the Future's type cannot be inferred you have to specify it, e.g. +/// +/// auto f = makeFuture(std::current_exception()); template Future makeFuture(std::exception_ptr const& e); @@ -176,19 +184,20 @@ makeFuture(E const& e); The Futures are moved in, so your copies are invalid. If you need to chain further from these Futures, use the variant with an output iterator. + XXX is this still true? This function is thread-safe for Futures running on different threads. - The return type for Future input is a Future>> + The return type for Future input is a Future>> */ template Future::value_type::value_type>>> whenAll(InputIterator first, InputIterator last); -/** This version takes a varying number of Futures instead of an iterator. - The return type for (Future, Future, ...) input - is a Future, Try, ...>>. - */ +/// This version takes a varying number of Futures instead of an iterator. +/// The return type for (Future, Future, ...) input +/// is a Future, Try, ...>>. +// XXX why does it take Fs& instead of Fs&&? template typename detail::VariadicContext::type whenAll(Fs&... fs); @@ -220,17 +229,3 @@ whenN(InputIterator first, InputIterator last, size_t n); }} // folly::wangle #include "Future-inl.h" - -/* - -TODO - -I haven't included a Future specialization because I don't forsee us -using it, however it is not difficult to add when needed. Refer to -Future for guidance. std::Future and boost::Future code would also be -instructive. - -I think that this might be a good candidate for folly, once it has baked for -awhile. - -*/