map()
[folly.git] / folly / futures / Future.h
1 /*
2  * Copyright 2015 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <algorithm>
20 #include <exception>
21 #include <functional>
22 #include <memory>
23 #include <type_traits>
24 #include <vector>
25
26 #include <folly/Optional.h>
27 #include <folly/MoveWrapper.h>
28 #include <folly/futures/Deprecated.h>
29 #include <folly/futures/DrivableExecutor.h>
30 #include <folly/futures/Promise.h>
31 #include <folly/futures/Try.h>
32 #include <folly/futures/FutureException.h>
33 #include <folly/futures/detail/Types.h>
34
35 namespace folly {
36
37 template <class> struct Promise;
38
39 template <typename T>
40 struct isFuture : std::false_type {
41   typedef T Inner;
42 };
43
44 template <typename T>
45 struct isFuture<Future<T>> : std::true_type {
46   typedef T Inner;
47 };
48
49 template <typename T>
50 struct isTry : std::false_type {};
51
52 template <typename T>
53 struct isTry<Try<T>> : std::true_type {};
54
55 namespace detail {
56
57 template <class> struct Core;
58 template <class...> struct VariadicContext;
59 template <class> struct CollectContext;
60
61 template<typename F, typename... Args>
62 using resultOf = decltype(std::declval<F>()(std::declval<Args>()...));
63
64 template <typename...>
65 struct ArgType;
66
67 template <typename Arg, typename... Args>
68 struct ArgType<Arg, Args...> {
69   typedef Arg FirstArg;
70 };
71
72 template <>
73 struct ArgType<> {
74   typedef void FirstArg;
75 };
76
77 template <bool isTry, typename F, typename... Args>
78 struct argResult {
79   typedef resultOf<F, Args...> Result;
80 };
81
82 template<typename F, typename... Args>
83 struct callableWith {
84     template<typename T,
85              typename = detail::resultOf<T, Args...>>
86     static constexpr std::true_type
87     check(std::nullptr_t) { return std::true_type{}; };
88
89     template<typename>
90     static constexpr std::false_type
91     check(...) { return std::false_type{}; };
92
93     typedef decltype(check<F>(nullptr)) type;
94     static constexpr bool value = type::value;
95 };
96
97 template<typename T, typename F>
98 struct callableResult {
99   typedef typename std::conditional<
100     callableWith<F>::value,
101     detail::argResult<false, F>,
102     typename std::conditional<
103       callableWith<F, T&&>::value,
104       detail::argResult<false, F, T&&>,
105       typename std::conditional<
106         callableWith<F, T&>::value,
107         detail::argResult<false, F, T&>,
108         typename std::conditional<
109           callableWith<F, Try<T>&&>::value,
110           detail::argResult<true, F, Try<T>&&>,
111           detail::argResult<true, F, Try<T>&>>::type>::type>::type>::type Arg;
112   typedef isFuture<typename Arg::Result> ReturnsFuture;
113   typedef Future<typename ReturnsFuture::Inner> Return;
114 };
115
116 template<typename F>
117 struct callableResult<void, F> {
118   typedef typename std::conditional<
119     callableWith<F>::value,
120     detail::argResult<false, F>,
121     typename std::conditional<
122       callableWith<F, Try<void>&&>::value,
123       detail::argResult<true, F, Try<void>&&>,
124       detail::argResult<true, F, Try<void>&>>::type>::type Arg;
125   typedef isFuture<typename Arg::Result> ReturnsFuture;
126   typedef Future<typename ReturnsFuture::Inner> Return;
127 };
128
129 template <typename L>
130 struct Extract : Extract<decltype(&L::operator())> { };
131
132 template <typename Class, typename R, typename... Args>
133 struct Extract<R(Class::*)(Args...) const> {
134   typedef isFuture<R> ReturnsFuture;
135   typedef Future<typename ReturnsFuture::Inner> Return;
136   typedef typename ReturnsFuture::Inner RawReturn;
137   typedef typename ArgType<Args...>::FirstArg FirstArg;
138 };
139
140 template <typename Class, typename R, typename... Args>
141 struct Extract<R(Class::*)(Args...)> {
142   typedef isFuture<R> ReturnsFuture;
143   typedef Future<typename ReturnsFuture::Inner> Return;
144   typedef typename ReturnsFuture::Inner RawReturn;
145   typedef typename ArgType<Args...>::FirstArg FirstArg;
146 };
147
148 } // detail
149
150 struct Timekeeper;
151
152 /// This namespace is for utility functions that would usually be static
153 /// members of Future, except they don't make sense there because they don't
154 /// depend on the template type (rather, on the type of their arguments in
155 /// some cases). This is the least-bad naming scheme we could think of. Some
156 /// of the functions herein have really-likely-to-collide names, like "map"
157 /// and "sleep".
158 namespace futures {
159   /// Returns a Future that will complete after the specified duration. The
160   /// Duration typedef of a `std::chrono` duration type indicates the
161   /// resolution you can expect to be meaningful (milliseconds at the time of
162   /// writing). Normally you wouldn't need to specify a Timekeeper, we will
163   /// use the global futures timekeeper (we run a thread whose job it is to
164   /// keep time for futures timeouts) but we provide the option for power
165   /// users.
166   ///
167   /// The Timekeeper thread will be lazily created the first time it is
168   /// needed. If your program never uses any timeouts or other time-based
169   /// Futures you will pay no Timekeeper thread overhead.
170   Future<void> sleep(Duration, Timekeeper* = nullptr);
171
172   /// Create a Future chain from a sequence of callbacks. i.e.
173   ///
174   ///   f.then(a).then(b).then(c);
175   ///
176   /// where f is a Future<A> and the result of the chain is a Future<Z>
177   /// becomes
178   ///
179   ///   f.then(chain<A,Z>(a, b, c));
180   // If anyone figures how to get chain to deduce A and Z, I'll buy you a drink.
181   template <class A, class Z, class... Callbacks>
182   std::function<Future<Z>(Try<A>)>
183   chain(Callbacks... fns);
184
185   /**
186    * Set func as the callback for each input Future and return a vector of
187    * Futures containing the results in the input order.
188    */
189   template <class It, class F,
190             class ItT = typename std::iterator_traits<It>::value_type,
191             class Result = decltype(std::declval<ItT>().then(std::declval<F>()))>
192   std::vector<Future<Result>> map(It first, It last, F func);
193
194 }
195
196 template <class T>
197 class Future {
198  public:
199   typedef T value_type;
200
201   // not copyable
202   Future(Future const&) = delete;
203   Future& operator=(Future const&) = delete;
204
205   // movable
206   Future(Future&&) noexcept;
207   Future& operator=(Future&&) noexcept;
208
209   // makeFuture
210   template <class F = T>
211   /* implicit */
212   Future(const typename std::enable_if<!std::is_void<F>::value, F>::type& val);
213
214   template <class F = T>
215   /* implicit */
216   Future(typename std::enable_if<!std::is_void<F>::value, F>::type&& val);
217
218   template <class F = T,
219             typename std::enable_if<std::is_void<F>::value, int>::type = 0>
220   Future();
221
222   ~Future();
223
224   /** Return the reference to result. Should not be called if !isReady().
225     Will rethrow the exception if an exception has been
226     captured.
227     */
228   typename std::add_lvalue_reference<T>::type
229   value();
230   typename std::add_lvalue_reference<const T>::type
231   value() const;
232
233   /// Returns an inactive Future which will call back on the other side of
234   /// executor (when it is activated).
235   ///
236   /// NB remember that Futures activate when they destruct. This is good,
237   /// it means that this will work:
238   ///
239   ///   f.via(e).then(a).then(b);
240   ///
241   /// a and b will execute in the same context (the far side of e), because
242   /// the Future (temporary variable) created by via(e) does not call back
243   /// until it destructs, which is after then(a) and then(b) have been wired
244   /// up.
245   ///
246   /// But this is still racy:
247   ///
248   ///   f = f.via(e).then(a);
249   ///   f.then(b);
250   // The ref-qualifier allows for `this` to be moved out so we
251   // don't get access-after-free situations in chaining.
252   // https://akrzemi1.wordpress.com/2014/06/02/ref-qualifiers/
253   template <typename Executor>
254   Future<T> via(Executor* executor) &&;
255
256   /// This variant creates a new future, where the ref-qualifier && version
257   /// moves `this` out. This one is less efficient but avoids confusing users
258   /// when "return f.via(x);" fails.
259   template <typename Executor>
260   Future<T> via(Executor* executor) &;
261
262   /** True when the result (or exception) is ready. */
263   bool isReady() const;
264
265   /** A reference to the Try of the value */
266   Try<T>& getTry();
267
268   /// If the promise has been fulfilled, return an Optional with the Try<T>.
269   /// Otherwise return an empty Optional.
270   /// Note that this moves the Try<T> out.
271   Optional<Try<T>> poll();
272
273   /// Block until the future is fulfilled. Returns the value (moved out), or
274   /// throws the exception. The future must not already have a callback.
275   T get();
276
277   /// Block until the future is fulfilled, or until timed out. Returns the
278   /// value (moved out), or throws the exception (which might be a TimedOut
279   /// exception).
280   T get(Duration dur);
281
282   /// Call e->drive() repeatedly until the future is fulfilled. Examples
283   /// of DrivableExecutor include EventBase and ManualExecutor. Returns the
284   /// value (moved out), or throws the exception.
285   T getVia(DrivableExecutor* e);
286
287   /// Unwraps the case of a Future<Future<T>> instance, and returns a simple
288   /// Future<T> instance.
289   template <class F = T>
290   typename std::enable_if<isFuture<F>::value,
291                           Future<typename isFuture<T>::Inner>>::type
292   unwrap();
293
294   /** When this Future has completed, execute func which is a function that
295     takes one of:
296       (const) Try<T>&&
297       (const) Try<T>&
298       (const) Try<T>
299       (const) T&&
300       (const) T&
301       (const) T
302       (void)
303
304     Func shall return either another Future or a value.
305
306     A Future for the return type of func is returned.
307
308     Future<string> f2 = f1.then([](Try<T>&&) { return string("foo"); });
309
310     The Future given to the functor is ready, and the functor may call
311     value(), which may rethrow if this has captured an exception. If func
312     throws, the exception will be captured in the Future that is returned.
313     */
314   /* TODO n3428 and other async frameworks have something like then(scheduler,
315      Future), we might want to support a similar API which could be
316      implemented a little more efficiently than
317      f.via(executor).then(callback) */
318   template <typename F, typename R = detail::callableResult<T, F>>
319   typename R::Return then(F func) {
320     typedef typename R::Arg Arguments;
321     return thenImplementation<F, R>(std::move(func), Arguments());
322   }
323
324   /// Variant where func is an member function
325   ///
326   ///   struct Worker { R doWork(Try<T>); }
327   ///
328   ///   Worker *w;
329   ///   Future<R> f2 = f1.then(&Worker::doWork, w);
330   ///
331   /// This is just sugar for
332   ///
333   ///   f1.then(std::bind(&Worker::doWork, w));
334   template <typename R, typename Caller, typename... Args>
335   Future<typename isFuture<R>::Inner>
336   then(R(Caller::*func)(Args...), Caller *instance);
337
338   /// Convenience method for ignoring the value and creating a Future<void>.
339   /// Exceptions still propagate.
340   Future<void> then();
341
342   /// Set an error callback for this Future. The callback should take a single
343   /// argument of the type that you want to catch, and should return a value of
344   /// the same type as this Future, or a Future of that type (see overload
345   /// below). For instance,
346   ///
347   /// makeFuture()
348   ///   .then([] {
349   ///     throw std::runtime_error("oh no!");
350   ///     return 42;
351   ///   })
352   ///   .onError([] (std::runtime_error& e) {
353   ///     LOG(INFO) << "std::runtime_error: " << e.what();
354   ///     return -1; // or makeFuture<int>(-1)
355   ///   });
356   template <class F>
357   typename std::enable_if<
358     !detail::callableWith<F, exception_wrapper>::value &&
359     !detail::Extract<F>::ReturnsFuture::value,
360     Future<T>>::type
361   onError(F&& func);
362
363   /// Overload of onError where the error callback returns a Future<T>
364   template <class F>
365   typename std::enable_if<
366     !detail::callableWith<F, exception_wrapper>::value &&
367     detail::Extract<F>::ReturnsFuture::value,
368     Future<T>>::type
369   onError(F&& func);
370
371   /// Overload of onError that takes exception_wrapper and returns Future<T>
372   template <class F>
373   typename std::enable_if<
374     detail::callableWith<F, exception_wrapper>::value &&
375     detail::Extract<F>::ReturnsFuture::value,
376     Future<T>>::type
377   onError(F&& func);
378
379   /// Overload of onError that takes exception_wrapper and returns T
380   template <class F>
381   typename std::enable_if<
382     detail::callableWith<F, exception_wrapper>::value &&
383     !detail::Extract<F>::ReturnsFuture::value,
384     Future<T>>::type
385   onError(F&& func);
386
387   /// func is like std::function<void()> and is executed unconditionally, and
388   /// the value/exception is passed through to the resulting Future.
389   /// func shouldn't throw, but if it does it will be captured and propagated,
390   /// and discard any value/exception that this Future has obtained.
391   template <class F>
392   Future<T> ensure(F func);
393
394   /// Like onError, but for timeouts. example:
395   ///
396   ///   Future<int> f = makeFuture<int>(42)
397   ///     .delayed(long_time)
398   ///     .onTimeout(short_time,
399   ///       []() -> int{ return -1; });
400   ///
401   /// or perhaps
402   ///
403   ///   Future<int> f = makeFuture<int>(42)
404   ///     .delayed(long_time)
405   ///     .onTimeout(short_time,
406   ///       []() { return makeFuture<int>(some_exception); });
407   template <class F>
408   Future<T> onTimeout(Duration, F&& func, Timekeeper* = nullptr);
409
410   /// This is not the method you're looking for.
411   ///
412   /// This needs to be public because it's used by make* and when*, and it's
413   /// not worth listing all those and their fancy template signatures as
414   /// friends. But it's not for public consumption.
415   template <class F>
416   void setCallback_(F&& func);
417
418   /// A Future's callback is executed when all three of these conditions have
419   /// become true: it has a value (set by the Promise), it has a callback (set
420   /// by then), and it is active (active by default).
421   ///
422   /// Inactive Futures will activate upon destruction.
423   Future<T>& activate() & {
424     core_->activate();
425     return *this;
426   }
427   Future<T>& deactivate() & {
428     core_->deactivate();
429     return *this;
430   }
431   Future<T> activate() && {
432     core_->activate();
433     return std::move(*this);
434   }
435   Future<T> deactivate() && {
436     core_->deactivate();
437     return std::move(*this);
438   }
439
440   bool isActive() {
441     return core_->isActive();
442   }
443
444   template <class E>
445   void raise(E&& exception) {
446     raise(make_exception_wrapper<typename std::remove_reference<E>::type>(
447         std::move(exception)));
448   }
449
450   /// Raise an interrupt. If the promise holder has an interrupt
451   /// handler it will be called and potentially stop asynchronous work from
452   /// being done. This is advisory only - a promise holder may not set an
453   /// interrupt handler, or may do anything including ignore. But, if you know
454   /// your future supports this the most likely result is stopping or
455   /// preventing the asynchronous operation (if in time), and the promise
456   /// holder setting an exception on the future. (That may happen
457   /// asynchronously, of course.)
458   void raise(exception_wrapper interrupt);
459
460   void cancel() {
461     raise(FutureCancellation());
462   }
463
464   /// Throw TimedOut if this Future does not complete within the given
465   /// duration from now. The optional Timeekeeper is as with futures::sleep().
466   Future<T> within(Duration, Timekeeper* = nullptr);
467
468   /// Throw the given exception if this Future does not complete within the
469   /// given duration from now. The optional Timeekeeper is as with
470   /// futures::sleep().
471   template <class E>
472   Future<T> within(Duration, E exception, Timekeeper* = nullptr);
473
474   /// Delay the completion of this Future for at least this duration from
475   /// now. The optional Timekeeper is as with futures::sleep().
476   Future<T> delayed(Duration, Timekeeper* = nullptr);
477
478   /// Block until this Future is complete. Returns a reference to this Future.
479   Future<T>& wait() &;
480
481   /// Overload of wait() for rvalue Futures
482   Future<T>&& wait() &&;
483
484   /// Block until this Future is complete or until the given Duration passes.
485   /// Returns a reference to this Future
486   Future<T>& wait(Duration) &;
487
488   /// Overload of wait(Duration) for rvalue Futures
489   Future<T>&& wait(Duration) &&;
490
491   /// Call e->drive() repeatedly until the future is fulfilled. Examples
492   /// of DrivableExecutor include EventBase and ManualExecutor. Returns a
493   /// reference to this Future so that you can chain calls if desired.
494   /// value (moved out), or throws the exception.
495   Future<T>& waitVia(DrivableExecutor* e) &;
496
497   /// Overload of waitVia() for rvalue Futures
498   Future<T>&& waitVia(DrivableExecutor* e) &&;
499
500   /// If the value in this Future is equal to the given Future, when they have
501   /// both completed, the value of the resulting Future<bool> will be true. It
502   /// will be false otherwise (including when one or both Futures have an
503   /// exception)
504   Future<bool> willEqual(Future<T>&);
505
506   /// predicate behaves like std::function<bool(T const&)>
507   /// If the predicate does not obtain with the value, the result
508   /// is a folly::PredicateDoesNotObtain exception
509   template <class F>
510   Future<T> filter(F predicate);
511
512  protected:
513   typedef detail::Core<T>* corePtr;
514
515   // shared core state object
516   corePtr core_;
517
518   explicit
519   Future(corePtr obj) : core_(obj) {}
520
521   void detach();
522
523   void throwIfInvalid() const;
524
525   friend class Promise<T>;
526   template <class> friend class Future;
527
528   // Variant: returns a value
529   // e.g. f.then([](Try<T> t){ return t.value(); });
530   template <typename F, typename R, bool isTry, typename... Args>
531   typename std::enable_if<!R::ReturnsFuture::value, typename R::Return>::type
532   thenImplementation(F func, detail::argResult<isTry, F, Args...>);
533
534   // Variant: returns a Future
535   // e.g. f.then([](Try<T> t){ return makeFuture<T>(t); });
536   template <typename F, typename R, bool isTry, typename... Args>
537   typename std::enable_if<R::ReturnsFuture::value, typename R::Return>::type
538   thenImplementation(F func, detail::argResult<isTry, F, Args...>);
539
540   Executor* getExecutor() { return core_->getExecutor(); }
541   void setExecutor(Executor* x) { core_->setExecutor(x); }
542 };
543
544 /**
545   Make a completed Future by moving in a value. e.g.
546
547     string foo = "foo";
548     auto f = makeFuture(std::move(foo));
549
550   or
551
552     auto f = makeFuture<string>("foo");
553 */
554 template <class T>
555 Future<typename std::decay<T>::type> makeFuture(T&& t);
556
557 /** Make a completed void Future. */
558 Future<void> makeFuture();
559
560 /** Make a completed Future by executing a function. If the function throws
561   we capture the exception, otherwise we capture the result. */
562 template <class F>
563 auto makeFutureTry(
564   F&& func,
565   typename std::enable_if<
566     !std::is_reference<F>::value, bool>::type sdf = false)
567   -> Future<decltype(func())>;
568
569 template <class F>
570 auto makeFutureTry(
571   F const& func)
572   -> Future<decltype(func())>;
573
574 /// Make a failed Future from an exception_ptr.
575 /// Because the Future's type cannot be inferred you have to specify it, e.g.
576 ///
577 ///   auto f = makeFuture<string>(std::current_exception());
578 template <class T>
579 Future<T> makeFuture(std::exception_ptr const& e) DEPRECATED;
580
581 /// Make a failed Future from an exception_wrapper.
582 template <class T>
583 Future<T> makeFuture(exception_wrapper ew);
584
585 /** Make a Future from an exception type E that can be passed to
586   std::make_exception_ptr(). */
587 template <class T, class E>
588 typename std::enable_if<std::is_base_of<std::exception, E>::value,
589                         Future<T>>::type
590 makeFuture(E const& e);
591
592 /** Make a Future out of a Try */
593 template <class T>
594 Future<T> makeFuture(Try<T>&& t);
595
596 /*
597  * Return a new Future that will call back on the given Executor.
598  * This is just syntactic sugar for makeFuture().via(executor)
599  *
600  * @param executor the Executor to call back on
601  *
602  * @returns a void Future that will call back on the given executor
603  */
604 template <typename Executor>
605 Future<void> via(Executor* executor);
606
607 /** When all the input Futures complete, the returned Future will complete.
608   Errors do not cause early termination; this Future will always succeed
609   after all its Futures have finished (whether successfully or with an
610   error).
611
612   The Futures are moved in, so your copies are invalid. If you need to
613   chain further from these Futures, use the variant with an output iterator.
614
615   This function is thread-safe for Futures running on different threads. But
616   if you are doing anything non-trivial after, you will probably want to
617   follow with `via(executor)` because it will complete in whichever thread the
618   last Future completes in.
619
620   The return type for Future<T> input is a Future<std::vector<Try<T>>>
621   */
622 template <class InputIterator>
623 Future<std::vector<Try<
624   typename std::iterator_traits<InputIterator>::value_type::value_type>>>
625 whenAll(InputIterator first, InputIterator last);
626
627 /// This version takes a varying number of Futures instead of an iterator.
628 /// The return type for (Future<T1>, Future<T2>, ...) input
629 /// is a Future<std::tuple<Try<T1>, Try<T2>, ...>>.
630 /// The Futures are moved in, so your copies are invalid.
631 template <typename... Fs>
632 typename detail::VariadicContext<
633   typename std::decay<Fs>::type::value_type...>::type
634 whenAll(Fs&&... fs);
635
636 /// Like whenAll, but will short circuit on the first exception. Thus, the
637 /// type of the returned Future is std::vector<T> instead of
638 /// std::vector<Try<T>>
639 template <class InputIterator>
640 Future<typename detail::CollectContext<
641   typename std::iterator_traits<InputIterator>::value_type::value_type
642 >::result_type>
643 collect(InputIterator first, InputIterator last);
644
645 /** The result is a pair of the index of the first Future to complete and
646   the Try. If multiple Futures complete at the same time (or are already
647   complete when passed in), the "winner" is chosen non-deterministically.
648
649   This function is thread-safe for Futures running on different threads.
650   */
651 template <class InputIterator>
652 Future<std::pair<
653   size_t,
654   Try<typename std::iterator_traits<InputIterator>::value_type::value_type>>>
655 whenAny(InputIterator first, InputIterator last);
656
657 /** when n Futures have completed, the Future completes with a vector of
658   the index and Try of those n Futures (the indices refer to the original
659   order, but the result vector will be in an arbitrary order)
660
661   Not thread safe.
662   */
663 template <class InputIterator>
664 Future<std::vector<std::pair<
665   size_t,
666   Try<typename std::iterator_traits<InputIterator>::value_type::value_type>>>>
667 whenN(InputIterator first, InputIterator last, size_t n);
668
669 template <typename F, typename T, typename ItT>
670 using MaybeTryArg = typename std::conditional<
671   detail::callableWith<F, T&&, Try<ItT>&&>::value, Try<ItT>, ItT>::type;
672
673 template<typename F, typename T, typename Arg>
674 using isFutureResult = isFuture<typename std::result_of<F(T&&, Arg&&)>::type>;
675
676 /** repeatedly calls func on every result, e.g.
677     reduce(reduce(reduce(T initial, result of first), result of second), ...)
678
679     The type of the final result is a Future of the type of the initial value.
680
681     Func can either return a T, or a Future<T>
682   */
683 template <class It, class T, class F,
684           class ItT = typename std::iterator_traits<It>::value_type::value_type,
685           class Arg = MaybeTryArg<F, T, ItT>>
686 typename std::enable_if<!isFutureResult<F, T, Arg>::value, Future<T>>::type
687 reduce(It first, It last, T initial, F func);
688
689 template <class It, class T, class F,
690           class ItT = typename std::iterator_traits<It>::value_type::value_type,
691           class Arg = MaybeTryArg<F, T, ItT>>
692 typename std::enable_if<isFutureResult<F, T, Arg>::value, Future<T>>::type
693 reduce(It first, It last, T initial, F func);
694
695 } // folly
696
697 #include <folly/futures/Future-inl.h>