#pragma once
#include <iostream>
#include <thread>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <atomic>

class TaskRunner {
public:
    TaskRunner() ;
    ~TaskRunner() ;

    // 添加任务
    void addTask(const std::function<void()>& task) ;

private:

 
    void run() ;

    std::thread worker;
    std::queue<std::function<void()>> tasks;
    std::mutex mtx;
    std::condition_variable cv;
    std::atomic<bool> stopFlag;
};