#pragma once
#include <concurrencpp/concurrencpp.h>
#include <atomic>
#include <chrono>
#include <exception>
#include <iostream>
#include <memory>
#include <sstream>
#include <utility>
#include <vector>

#include "Core/Statistics/Frequency_Limit.h"
#include "Local_Server/Data_Feed/Data_Feed.h"
#include "Local_Server/Data_Source/Data_Source.h"
class Coro {
public:
    void start();
    void stop();
private:
    bool task_is_running(std::unique_ptr<concurrencpp::result<void>>& task);
    concurrencpp::result<void> data_source_loop_coro(std::shared_ptr<Data_Source> source);
    concurrencpp::result<void> data_feed_loop_coro(std::shared_ptr<Data_Feed> feed);
    concurrencpp::result<void> coro_thread();
    bool has_running_loop_tasks();
    Frequency_Limit too_many_msg_limit;
    Frequency_Limit flush_limit;
    concurrencpp::runtime runtime_;
    std::shared_ptr<concurrencpp::worker_thread_executor> executor_;
    std::unique_ptr<concurrencpp::result<void>> data_feed_thread_task;
    std::atomic<bool> running = false;
};
