From fcabeed7544285f3244465ccfc5337c59e63c6b0 Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 11 Jan 2017 23:45:03 +0100 Subject: Core/DBLayer: Added new async query callback api --- src/server/database/Database/QueryCallback.h | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/server/database/Database/QueryCallback.h') diff --git a/src/server/database/Database/QueryCallback.h b/src/server/database/Database/QueryCallback.h index 73e53dbe3f4..a0aa69ee952 100644 --- a/src/server/database/Database/QueryCallback.h +++ b/src/server/database/Database/QueryCallback.h @@ -28,6 +28,61 @@ typedef std::promise PreparedQueryResultPromise; #define CALLBACK_STAGE_INVALID uint8(-1) +class TC_DATABASE_API QueryCallbackNew +{ + struct String + { + explicit String(std::future&& result) : Result(std::move(result)) { } + String(String&&) = default; + String& operator=(String&&) = default; + ~String() { } + + std::future Result; + std::function Callback; + }; + + struct Prepared + { + explicit Prepared(std::future&& result) : Result(std::move(result)) { } + Prepared(Prepared&&) = default; + Prepared& operator=(Prepared&&) = default; + ~Prepared() { } + + std::future Result; + std::function Callback; + }; + +public: + explicit QueryCallbackNew(std::future&& result); + explicit QueryCallbackNew(std::future&& result); + QueryCallbackNew(QueryCallbackNew&& right); + QueryCallbackNew& operator=(QueryCallbackNew&& right); + ~QueryCallbackNew(); + + QueryCallbackNew&& WithCallback(std::function&& callback); + QueryCallbackNew&& WithPreparedCallback(std::function&& callback); + + enum Status + { + NotReady, + NextStep, + Completed + }; + + Status InvokeIfReady(); + +private: + void MoveFrom(QueryCallbackNew&& other); + void DestroyCurrentMember(); + + union + { + String _string; + Prepared _prepared; + }; + bool _isPrepared; +}; + template class QueryCallback { -- cgit v1.2.3