folly: specialise makeFutureWith for functions returning futures
authorSven Over <over@fb.com>
Wed, 2 Sep 2015 10:13:17 +0000 (03:13 -0700)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Wed, 2 Sep 2015 10:20:18 +0000 (03:20 -0700)
commit823a8c0198d3f72b0cf6fa2efec8ba47d9a4d644
treedd3c7499fe71eb8663bf4a3bb92cad27ea247a02
parentf119064488072b6a228cdb65e1ac8f1c5f37d2bb
folly: specialise makeFutureWith for functions returning futures

Summary: makeFutureWith executes a function and returns a future containing
set to the function's return value. This diff adds a specialisation
for the case when the function returns some type Future<T>. Instead
of returning Future<Future<T>>, makeFutureWith now just passes
on the future that the function returned, which may or may not have
a value set at this time. In case the function throws,
makeFutureWith returns a Future<T> containing the exception.

With this diff, the following two lines produce equivalent results:
  auto f1 = makeFutureWith(func);
  auto f2 = makeFuture().then(func);
except for the fact that f2 requires an additional temporary
Future<Unit> to be created and destroyed.

Reviewed By: @fugalh

Differential Revision: D2388335
folly/futures/Future-inl.h
folly/futures/helpers.h
folly/futures/test/FutureTest.cpp