#pragma once #include #include #include #include #include #include #include #include namespace NYql { class TAsyncQueue: public TThrRefBase { public: using TPtr = TIntrusivePtr; static TPtr Make(size_t numThreads, const TString& poolName); void Stop() { auto guard = TWriteGuard(Lock_); if (MtpQueue_) { MtpQueue_->Stop(); MtpQueue_.Destroy(); } } template [[nodiscard]] ::NThreading::TFuture<::NThreading::TFutureType<::TFunctionResult>> Async(TCallable&& func) { { auto guard = TReadGuard(Lock_); if (MtpQueue_) { return ::NThreading::Async(std::move(func), *MtpQueue_); } } return ::NThreading::MakeErrorFuture<::NThreading::TFutureType<::TFunctionResult>>(std::make_exception_ptr(yexception() << "Thread pool is already stopped")); } private: TAsyncQueue(size_t numThreads, const TString& poolName); private: TRWMutex Lock_; THolder MtpQueue_; }; } // NYql