<commit_before>#ifndef EE_X_LAMBDA_AWAITER_HPP
#define EE_X_LAMBDA_AWAITER_HPP

#include <experimental/coroutine>
#include <functional>
#include <vector>

#include "ee/CoroutineFwd.hpp"

namespace ee {
namespace coroutine {
template <class Result>
struct LambdaAwaiter {
public:
    using Resolve = std::function<void(Result result)>;
    using Function = std::function<void(const Resolve& resolve)>;

    explicit LambdaAwaiter(const Function& f)
        : f_(f)
        , invoked_(false)
        , ready_(false) {}

    LambdaAwaiter(const LambdaAwaiter&) = delete;

    LambdaAwaiter(LambdaAwaiter&& other)
        : f_(std::exchange(other.f_, nullptr))
        , invoked_(std::exchange(other.invoked_, false))
        , ready_(std::exchange(other.ready_, false))
        , result_(std::exchange(other.result_, Result()))
        , handles_(std::exchange(other.handles_, {})) {}

    void await_suspend(std::experimental::coroutine_handle<> handle) {
        handles_.push_back(handle);
        if (invoked_) {
            // Waiting.
        } else {
            invoked_ = true;
            f_([this, handle](Result result) mutable {
                ready_ = true;
                result_ = result;
                for (auto&& handle : handles_) {
                    handle.resume();
                }
            });
        }
    }

    bool await_ready() { //
        return ready_;
    }

    Result await_resume() { //
        return result_;
    }

private:
    Function f_;
    bool invoked_;
    bool ready_;
    Result result_;
    std::vector<std::experimental::coroutine_handle<>> handles_;
};

template <>
struct LambdaAwaiter<void> {
    using Resolve = std::function<void()>;
    using Function = std::function<void(const Resolve& resolve)>;

    explicit LambdaAwaiter(const Function& f)
        : f_(f)
        , invoked_(false)
        , ready_(false) {}

    LambdaAwaiter(const LambdaAwaiter&) = delete;

    LambdaAwaiter(LambdaAwaiter&& other)
        : f_(std::exchange(other.f_, nullptr))
        , invoked_(std::exchange(other.invoked_, false))
        , ready_(std::exchange(other.ready_, false))
        , handles_(std::exchange(other.handles_, {})) {
        int x = 1;
    }

    ~LambdaAwaiter() { //
        int x = 1;
    }

    void await_suspend(std::experimental::coroutine_handle<> handle) {
        handles_.push_back(handle);
        if (invoked_) {
            // Waiting.
        } else {
            invoked_ = true;
            f_([this]() mutable {
                ready_ = true;
                for (auto&& handle : handles_) {
                    handle.resume();
                }
            });
        }
    }

    bool await_ready() { //
        return ready_;
    }

    void await_resume() {}

private:
    Function f_;
    bool invoked_;
    bool ready_;
    std::vector<std::experimental::coroutine_handle<>> handles_;
};<commit_msg>Remove unused params.<commit_after>#ifndef EE_X_LAMBDA_AWAITER_HPP
#define EE_X_LAMBDA_AWAITER_HPP

#include <experimental/coroutine>
#include <functional>
#include <vector>

#include "ee/CoroutineFwd.hpp"

namespace ee {
namespace coroutine {
template <class Result>
struct LambdaAwaiter {
public:
    using Resolve = std::function<void(Result result)>;
    using Function = std::function<void(const Resolve& resolve)>;

    explicit LambdaAwaiter(const Function& f)
        : f_(f)
        , invoked_(false)
        , ready_(false) {}

    LambdaAwaiter(const LambdaAwaiter&) = delete;

    LambdaAwaiter(LambdaAwaiter&& other)
        : f_(std::exchange(other.f_, nullptr))
        , invoked_(std::exchange(other.invoked_, false))
        , ready_(std::exchange(other.ready_, false))
        , result_(std::exchange(other.result_, Result()))
        , handles_(std::exchange(other.handles_, {})) {}

    void await_suspend(std::experimental::coroutine_handle<> handle) {
        handles_.push_back(handle);
        if (invoked_) {
            // Waiting.
        } else {
            invoked_ = true;
            f_([this, handle](Result result) mutable {
                ready_ = true;
                result_ = result;
                for (auto&& handle : handles_) {
                    handle.resume();
                }
            });
        }
    }

    bool await_ready() { //
        return ready_;
    }

    Result await_resume() { //
        return result_;
    }

private:
    Function f_;
    bool invoked_;
    bool ready_;
    Result result_;
    std::vector<std::experimental::coroutine_handle<>> handles_;
};

template <>
struct LambdaAwaiter<void> {
    using Resolve = std::function<void()>;
    using Function = std::function<void(const Resolve& resolve)>;

    explicit LambdaAwaiter(const Function& f)
        : f_(f)
        , invoked_(false)
        , ready_(false) {}

    LambdaAwaiter(const LambdaAwaiter&) = delete;

    LambdaAwaiter(LambdaAwaiter&& other)
        : f_(std::exchange(other.f_, nullptr))
        , invoked_(std::exchange(other.invoked_, false))
        , ready_(std::exchange(other.ready_, false))
        , handles_(std::exchange(other.handles_, {})) {}

    void await_suspend(std::experimental::coroutine_handle<> handle) {
        handles_.push_back(handle);
        if (invoked_) {
            // Waiting.
        } else {
            invoked_ = true;
            f_([this]() mutable {
                ready_ = true;
                for (auto&& handle : handles_) {
                    handle.resume();
                }
            });
        }
    }

    bool await_ready() { //
        return ready_;
    }

    void await_resume() {}

private:
    Function f_;
    bool invoked_;
    bool ready_;
    std::vector<std::experimental::coroutine_handle<>> handles_;
};
{'fraction_non_alphanumeric': 0.1277116864940518, 'fraction_numerical': 0.0003498950314905528, 'mean_word_length': 2.2631278538812785, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5430963', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1708, 'n_words': 325}