<commit_before>/*
 * Copyright 2015 Facebook, Inc.
 *
 * 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/futures/Promise.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 will be
 * called back. 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.
 */
template <class T>
class SharedPromise {
public:
  SharedPromise() = default;
  ~SharedPromise() = default;

  // not copyable
  SharedPromise(SharedPromise const&) = delete;
  SharedPromise& operator=(SharedPromise const&) = delete;

  // movable
  SharedPromise(SharedPromise<T>&&) noexcept;
  SharedPromise& operator=(SharedPromise<T>&&) noexcept;

  /** Return a Future tied to the shared core state. This can be called only
    once, thereafter Future already retrieved exception will be raised. */
  Future<T> getFuture();

  /** Return the number of Futures associated with this SharedPromise */
  size_t size();

  /** Fulfill the SharedPromise with an exception_wrapper */
  void setException(exception_wrapper ew);

  /** Fulfill the SharedPromise with an exception_ptr, e.g.
    try {
      ...
    } catch (...) {
      p.setException(std::current_exception());
    }
    */
  void setException(std::exception_ptr const&) DEPRECATED;<commit_msg>fix typo in SharedPromise comment<commit_after>/*
 * Copyright 2015 Facebook, Inc.
 *
 * 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/futures/Promise.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 will be
 * called back. 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.
 */
template <class T>
class SharedPromise {
public:
  SharedPromise() = default;
  ~SharedPromise() = default;

  // not copyable
  SharedPromise(SharedPromise const&) = delete;
  SharedPromise& operator=(SharedPromise const&) = delete;

  // movable
  SharedPromise(SharedPromise<T>&&) noexcept;
  SharedPromise& operator=(SharedPromise<T>&&) noexcept;

  /**
   * Return a Future tied to the shared core state. Unlike Promise::getFuture,
   * this can be called an unlimited number of times per SharedPromise.
   */
  Future<T> getFuture();

  /** Return the number of Futures associated with this SharedPromise */
  size_t size();

  /** Fulfill the SharedPromise with an exception_wrapper */
  void setException(exception_wrapper ew);

  /** Fulfill the SharedPromise with an exception_ptr, e.g.
    try {
      ...
    } catch (...) {
      p.setException(std::current_exception());
    }
    */
  void setException(std::exception_ptr const&) DEPRECATED;
{'fraction_non_alphanumeric': 0.08491572434393002, 'fraction_numerical': 0.0034136974610625135, 'mean_word_length': 3.9503695881731784, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5499042', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1202, 'n_words': 546}