folly/folly/futures/SharedPromise.h

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <folly/Portability.h>
#include <folly/executors/InlineExecutor.h>
#include <folly/futures/Promise.h>
#include <folly/lang/Exception.h>

namespace folly {

/*
 * SharedPromise provides the same interface as Promise, but you can extract
 * multiple Futures from it, i.e. you can call getFuture() as many times as
 * you'd like. When the SharedPromise is fulfilled, all of the Futures are
 * completed. Calls to getFuture() after the SharedPromise is fulfilled return
 * a completed Future. If you find yourself constructing collections of Promises
 * and fulfilling them simultaneously with the same value, consider this
 * utility instead. Likewise, if you find yourself in need of setting multiple
 * callbacks on the same Future (which is indefinitely unsupported), consider
 * refactoring to use SharedPromise to "split" the Future.
 *
 * The SharedPromise must be kept alive manually. Consider FutureSplitter for
 * automatic lifetime management.
 */
template <class T>
class SharedPromise {};

} // namespace folly

#include <folly/futures/Future.h>
#include <folly/futures/SharedPromise-inl.h>