@@ -25,9 +25,7 @@ template <typename E> struct ExecutorAdaptor {
2525 template <typename ... Args>
2626 ExecutorAdaptor (Args &&... args) : ex(std::forward<Args>(args)...) {}
2727
28- void submit (std::function<void ()> f) {
29- ex.submit (std::move (f));
30- }
28+ void submit (std::function<void ()> f) { ex.submit (std::move (f)); }
3129
3230 E ex;
3331};
@@ -53,13 +51,16 @@ template <typename T> class Future {
5351 }
5452
5553 template <typename F>
56- Future<absl::result_of_t <typename std::decay<F>::type(typename TryWrapper<T>::type)>> Then (Lauch policy, F &&fn) {
54+ Future<absl::result_of_t <
55+ typename std::decay<F>::type(typename TryWrapper<T>::type)>>
56+ Then (Lauch policy, F &&fn) {
5757 return ThenImpl (policy, (EmptyExecutor *)nullptr , std::forward<F>(fn));
5858 }
5959
6060 template <typename F, typename Ex>
61- Future<absl::result_of_t <typename std::decay<F>::type(typename TryWrapper<T>::type)>> Then (Ex* executor,
62- F &&fn) {
61+ Future<absl::result_of_t <
62+ typename std::decay<F>::type(typename TryWrapper<T>::type)>>
63+ Then (Ex *executor, F &&fn) {
6364 return ThenImpl (Lauch::Async, executor, std::forward<F>(fn));
6465 }
6566
@@ -98,11 +99,10 @@ template <typename T> class Future {
9899 void Wait () { shared_state_->Wait (); }
99100
100101private:
101-
102- template <typename FirstArg, typename F, typename Executor, typename U>
103- static void ExecuteTask (Lauch policy, Executor *executor, MoveWrapper<F> func,
104- MoveWrapper<Promise<U>> next_prom,
105- std::shared_ptr<SharedState<T>> const & state);
102+ template <typename FirstArg, typename F, typename Executor, typename U>
103+ static void ExecuteTask (Lauch policy, Executor *executor, MoveWrapper<F> func,
104+ MoveWrapper<Promise<U>> next_prom,
105+ std::shared_ptr<SharedState<T>> const &state);
106106
107107 template <typename F, typename Ex>
108108 Future<typename function_traits<F>::return_type>
@@ -120,10 +120,10 @@ template <typename T> class Future {
120120
121121 std::unique_lock<std::mutex> lock (shared_state_->then_mtx_ );
122122 if (shared_state_->state_ == FutureStatus::None) {
123- shared_state_->continuations_ .emplace_back ([policy, executor, func, next_prom,
124- state]() mutable {
125- ExecuteTask<FirstArg>(policy, executor, func, next_prom, state);
126- });
123+ shared_state_->continuations_ .emplace_back (
124+ [policy, executor, func, next_prom, state]() mutable {
125+ ExecuteTask<FirstArg>(policy, executor, func, next_prom, state);
126+ });
127127 } else if (shared_state_->state_ == FutureStatus::Done) {
128128 lock.unlock ();
129129 ExecuteTask<FirstArg>(policy, executor, func, next_prom, shared_state_);
@@ -266,7 +266,8 @@ template <typename F, typename... Args>
266266inline Future<
267267 absl::result_of_t <typename std::decay<F>::type(absl::decay_t <Args>...)>>
268268Async (F &&fn, Args &&... args) {
269- return future_internal::AsyncImpl (Lauch::Async, (EmptyExecutor*)nullptr , std::forward<F>(fn),
269+ return future_internal::AsyncImpl (Lauch::Async, (EmptyExecutor *)nullptr ,
270+ std::forward<F>(fn),
270271 std::forward<Args>(args)...);
271272}
272273
@@ -425,30 +426,31 @@ WhenAll(F &&... futures) {
425426
426427template <typename T>
427428template <typename FirstArg, typename F, typename Executor, typename U>
428- void Future<T>::ExecuteTask(Lauch policy, Executor *executor, MoveWrapper<F> func,
429- MoveWrapper<Promise<U>> next_prom,
430- std::shared_ptr<SharedState<T>> const & state) {
429+ void Future<T>::ExecuteTask(Lauch policy, Executor *executor,
430+ MoveWrapper<F> func,
431+ MoveWrapper<Promise<U>> next_prom,
432+ std::shared_ptr<SharedState<T>> const &state) {
431433 auto task = [func, state, next_prom]() mutable {
432434 try {
433435 auto result = Invoke<FirstArg>(func.move (), state->value_ );
434- next_prom->SetValue (std::move (result));
435- } catch (...) {
436- next_prom->SetException (std::current_exception ());
437- }
438- };
439-
440- if (executor){
441- executor->submit (std::move (task));
442- return ;
436+ next_prom->SetValue (std::move (result));
437+ } catch (...) {
438+ next_prom->SetException (std::current_exception ());
443439 }
440+ };
444441
445- if (policy == Lauch::Async) {
446- Async (std::move (task));
447- } else {
448- task ();
449- }
442+ if (executor) {
443+ executor->submit (std::move (task));
444+ return ;
445+ }
446+
447+ if (policy == Lauch::Async) {
448+ Async (std::move (task));
449+ } else {
450+ task ();
450451 }
451452}
453+ }
452454
453455
454456
0 commit comments