/*
 * core/worker_pool.h — fixed-size thread pool for blocking work.
 *
 * Used for Argon2id password hashing (deliberately slow) and TLS handshakes so
 * neither blocks the net thread. Real-time audio threads never use this.
 *
 * Requires VOICECAT_HAS_NET (Asio). Undefined when building without deps.
 */
#ifndef VOICECAT_CORE_WORKER_POOL_H
#define VOICECAT_CORE_WORKER_POOL_H

#ifdef VOICECAT_HAS_NET

#include <asio/thread_pool.hpp>
#include <asio/post.hpp>
#include <cstddef>
#include <utility>

namespace voicecat {

class WorkerPool {
   public:
    explicit WorkerPool(std::size_t threads = 3) : pool_(threads) {}
    ~WorkerPool() { pool_.join(); }

    template <typename F>
    void post(F&& fn) {
        asio::post(pool_, std::forward<F>(fn));
    }

    // Wait for all outstanding tasks to finish.
    void join() { pool_.join(); }

   private:
    asio::thread_pool pool_;
};

}  // namespace voicecat

#endif  // VOICECAT_HAS_NET
#endif  // VOICECAT_CORE_WORKER_POOL_H
