diff options
author | Shauren <shauren.trinity@gmail.com> | 2017-01-11 23:45:03 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2017-01-11 23:45:03 +0100 |
commit | fcabeed7544285f3244465ccfc5337c59e63c6b0 (patch) | |
tree | 49d09527fb6e43738e12b52fbfc38030c0b4b46d /src/server/database/Database/QueryCallback.h | |
parent | 1cb9d05e29a333a49014ca10230f8a490928c3d0 (diff) |
Core/DBLayer: Added new async query callback api
Diffstat (limited to 'src/server/database/Database/QueryCallback.h')
-rw-r--r-- | src/server/database/Database/QueryCallback.h | 55 |
1 files changed, 55 insertions, 0 deletions
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<PreparedQueryResult> PreparedQueryResultPromise; #define CALLBACK_STAGE_INVALID uint8(-1) +class TC_DATABASE_API QueryCallbackNew +{ + struct String + { + explicit String(std::future<QueryResult>&& result) : Result(std::move(result)) { } + String(String&&) = default; + String& operator=(String&&) = default; + ~String() { } + + std::future<QueryResult> Result; + std::function<void(QueryResult)> Callback; + }; + + struct Prepared + { + explicit Prepared(std::future<PreparedQueryResult>&& result) : Result(std::move(result)) { } + Prepared(Prepared&&) = default; + Prepared& operator=(Prepared&&) = default; + ~Prepared() { } + + std::future<PreparedQueryResult> Result; + std::function<void(PreparedQueryResult)> Callback; + }; + +public: + explicit QueryCallbackNew(std::future<QueryResult>&& result); + explicit QueryCallbackNew(std::future<PreparedQueryResult>&& result); + QueryCallbackNew(QueryCallbackNew&& right); + QueryCallbackNew& operator=(QueryCallbackNew&& right); + ~QueryCallbackNew(); + + QueryCallbackNew&& WithCallback(std::function<void(QueryResult)>&& callback); + QueryCallbackNew&& WithPreparedCallback(std::function<void(PreparedQueryResult)>&& callback); + + enum Status + { + NotReady, + NextStep, + Completed + }; + + Status InvokeIfReady(); + +private: + void MoveFrom(QueryCallbackNew&& other); + void DestroyCurrentMember(); + + union + { + String _string; + Prepared _prepared; + }; + bool _isPrepared; +}; + template <typename Result, typename ParamType, bool chain = false> class QueryCallback { |