MCPcopy Create free account
hub / github.com/apache/arrow / Future

Class Future

cpp/src/arrow/util/future.h:318–685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316/// to complete, and composing futures with callbacks.
317template <typename T>
318class [[nodiscard]] Future {
319 public:
320 using ValueType = T;
321 using SyncType = typename detail::SyncType<T>::type;
322 static constexpr bool is_empty = std::is_same<T, internal::Empty>::value;
323 // The default constructor creates an invalid Future. Use Future::Make()
324 // for a valid Future. This constructor is mostly for the convenience
325 // of being able to presize a vector of Futures.
326 Future() = default;
327
328#ifdef ARROW_WITH_OPENTELEMETRY
329 void SetSpan(util::tracing::Span* span) { impl_->SetSpan(span); }
330#endif
331
332 // Consumer API
333
334 bool is_valid() const { return impl_ != NULLPTR; }
335
336 /// \brief Return the Future's current state
337 ///
338 /// A return value of PENDING is only indicative, as the Future can complete
339 /// concurrently. A return value of FAILURE or SUCCESS is definitive, though.
340 FutureState state() const {
341 CheckValid();
342 return impl_->state();
343 }
344
345 /// \brief Whether the Future is finished
346 ///
347 /// A false return value is only indicative, as the Future can complete
348 /// concurrently. A true return value is definitive, though.
349 bool is_finished() const {
350 CheckValid();
351 return IsFutureFinished(impl_->state());
352 }
353
354 /// \brief Wait for the Future to complete and return its Result
355 const Result<ValueType>& result() const& {
356 Wait();
357 return *GetResult();
358 }
359
360 /// \brief Returns an rvalue to the result. This method is potentially unsafe
361 ///
362 /// The future is not the unique owner of the result, copies of a future will
363 /// also point to the same result. You must make sure that no other copies
364 /// of the future exist. Attempts to add callbacks after you move the result
365 /// will result in undefined behavior.
366 Result<ValueType>&& MoveResult() {
367 Wait();
368 return std::move(*GetResult());
369 }
370
371 /// \brief Wait for the Future to complete and return its Status
372 const Status& status() const { return result().status(); }
373
374 /// \brief Future<T> is convertible to Future<>, which views only the
375 /// Status of the original. Marking the returned Future Finished is not supported.

Callers

nothing calls this directly

Calls 2

resultFunction · 0.85
statusMethod · 0.45

Tested by

no test coverage detected