/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#pragma once
-#include <folly/futures/Promise.h>
#include <folly/Portability.h>
+#include <folly/executors/InlineExecutor.h>
+#include <folly/futures/Promise.h>
namespace folly {
*/
template <class T>
class SharedPromise {
-public:
+ public:
SharedPromise() = default;
~SharedPromise() = default;
SharedPromise& operator=(SharedPromise<T>&&) noexcept;
/**
- * Provide a way to split a Future<T>. Note that while the Futures from
- * `getFuture()' depend on the completion of the parameter Future they do not
- * inherit any other properties such as Executor's passed to `via' etc.
+ * Return a Future tied to the shared core state. Unlike Promise::getFuture,
+ * this can be called an unlimited number of times per SharedPromise.
*/
- explicit SharedPromise(Future<T>);
+ SemiFuture<T> getSemiFuture();
/**
* Return a Future tied to the shared core state. Unlike Promise::getFuture,
* this can be called an unlimited number of times per SharedPromise.
+ * NOTE: This function is deprecated. Please use getSemiFuture and pass the
+ * appropriate executor to .via on the returned SemiFuture to get a
+ * valid Future where necessary.
*/
Future<T> getFuture();
bool isFulfilled();
-private:
+ private:
std::mutex mutex_;
size_t size_{0};
bool hasValue_{false};
std::function<void(exception_wrapper const&)> interruptHandler_;
};
-}
+} // namespace folly
#include <folly/futures/Future.h>
#include <folly/futures/SharedPromise-inl.h>