#pragma once
#include <trantor/net/EventLoop.h>
#include <trantor/utils/NonCopyable.h>
#include <trantor/exports.h>
#include <mutex>
#include <thread>
#include <memory>
#include <condition_variable>
#include <future>
namespace trantor
{
class TRANTOR_EXPORT EventLoopThread : NonCopyable
{
  public:
    explicit EventLoopThread(const std::string &threadName = "EventLoopThread");
    ~EventLoopThread();
    void wait();
    EventLoop *getLoop() const
    {
        return loop_.get();
    }
    void run();
  private:
    std::shared_ptr<EventLoop> loop_;
    std::mutex loopMutex_;
    std::string loopThreadName_;
    void loopFuncs();
    std::promise<std::shared_ptr<EventLoop>> promiseForLoopPointer_;
    std::promise<int> promiseForRun_;
    std::promise<int> promiseForLoop_;
    std::once_flag once_;
    std::thread thread_;
};
}  