X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ffutures%2FPromise.h;h=379ad5d6fdc2b5c273a1cfeb5ff44110936370d6;hb=0afc127248ddfd944ec11648ff066d783b87c078;hp=e39ea57f0d2ff9e06ae11547ee9a7994666f109b;hpb=a0a9fc4547c535b3bb0dd7192dc065ee1cedcc82;p=folly.git diff --git a/folly/futures/Promise.h b/folly/futures/Promise.h index e39ea57f..379ad5d6 100644 --- a/folly/futures/Promise.h +++ b/folly/futures/Promise.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include @@ -53,7 +53,8 @@ public: p.setException(std::current_exception()); } */ - void setException(std::exception_ptr const&) DEPRECATED; + FOLLY_DEPRECATED("use setException(exception_wrapper)") + void setException(std::exception_ptr const&); /** Fulfill the Promise with an exception type E, which can be passed to std::make_exception_ptr(). Useful for originating exceptions. If you @@ -70,14 +71,18 @@ public: /// handled. void setInterruptHandler(std::function); - /** Fulfill this Promise (only for Promise) */ - void setValue(); + /// Sugar to fulfill this Promise + template + typename std::enable_if::value, void>::type + setValue() { + setTry(Try(T())); + } /** Set the value (use perfect forwarding for both move and copy) */ template void setValue(M&& value); - void setTry(Try t); + void setTry(Try&& t); /** Fulfill this Promise with the result of a function that takes no arguments and returns something implicitly convertible to T. @@ -88,8 +93,11 @@ public: template void setWith(F&& func); + bool isFulfilled(); + private: typedef typename Future::corePtr corePtr; + template friend class Future; // Whether the Future has been retrieved (a one-time operation). bool retrieved_;