Commit ad710a56 authored by Hans Fugal's avatar Hans Fugal Committed by Nicholas Ormrod

nuke executeWith

Summary: Removing this crufty API. The only callsite for `executeWith` was `Later::via` so I just folded it in there.

Test Plan:
unit tests
contbuild

Reviewed By: hannesr@fb.com

Subscribers: net-systems@, fugalh, exa

FB internal diff: D1406592

Tasks: 4480567
parent 57a00d50
......@@ -199,22 +199,6 @@ inline Future<T> Future<T>::via(Executor* executor) {
return f;
}
template <class T>
template <typename Executor>
inline void Future<T>::executeWith(
Executor* executor, Promise<T>&& cont_promise) {
throwIfInvalid();
folly::MoveWrapper<Promise<T>> p(std::move(cont_promise));
setContinuation([executor, p](Try<T>&& t) mutable {
folly::MoveWrapper<Try<T>> tt(std::move(t));
executor->add([p, tt]() mutable {
p->fulfilTry(std::move(*tt));
});
});
}
template <class T>
bool Future<T>::isReady() const {
throwIfInvalid();
......
......@@ -71,28 +71,6 @@ class Future {
template <typename Executor>
Future<T> via(Executor* executor);
/// Deprecated alias for via
template <typename Executor>
Future<T> executeWithSameThread(Executor* executor) {
return via(executor);
}
/**
Thread-safe version of executeWith
Since an executor would likely start executing the Future chain
right away, it would be a race condition to call:
Future.executeWith(...).then(...), as there would be race
condition between the then and the running Future.
Instead, you may pass in a Promise so that we can set up
the rest of the chain in advance, without any racey
modifications of the continuation
Deprecated. Use a Later.
*/
template <typename Executor>
void executeWith(Executor* executor, Promise<T>&& cont_promise);
/** True when the result (or exception) is ready. */
bool isReady() const;
......@@ -111,7 +89,8 @@ class Future {
*/
/* TODO n3428 and other async frameworks have something like then(scheduler,
Future), we probably want to support a similar API (instead of
executeWith). */
via. or rather, via should return a cold future (Later) and we provide
then(scheduler, Future) ). */
template <class F>
typename std::enable_if<
!isFuture<typename std::result_of<F(Try<T>&&)>::type>::value,
......@@ -196,8 +175,11 @@ class Future {
/// Exceptions still propagate.
Future<void> then();
/// Use of this method is advanced wizardry.
/// XXX should this be protected?
/// This is not the method you're looking for.
///
/// This needs to be public because it's used by make* and when*, and it's
/// not worth listing all those and their fancy template signatures as
/// friends. But it's not for public consumption.
template <class F>
void setContinuation(F&& func);
......
......@@ -130,10 +130,17 @@ Later<T>::then(F&& fn) {
template <class T>
Later<T> Later<T>::via(Executor* executor) {
Promise<T> promise;
folly::MoveWrapper<Promise<T>> promise;
Later<T> later(std::move(starter_));
later.future_ = promise.getFuture();
future_->executeWith(executor, std::move(promise));
later.future_ = promise->getFuture();
future_->setContinuation([executor, promise](Try<T>&& t) mutable {
folly::MoveWrapper<Try<T>> tt(std::move(t));
executor->add([promise, tt]() mutable {
promise->fulfilTry(std::move(*tt));
});
});
return later;
}
......
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