aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/Database/QueryCallback.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2017-01-11 23:45:03 +0100
committerariel- <ariel-@users.noreply.github.com>2017-01-25 23:38:07 -0300
commitb879a6cae5e31ef382a5b52fa19a726a061e9aca (patch)
tree778fac936e8edce84c4128432f1d166f7875e105 /src/server/database/Database/QueryCallback.h
parent62b62ddd63942090b23f8881f2c6ad93d0a251dc (diff)
Core/DBLayer: Added new async query callback api
(cherry picked from commit fcabeed7544285f3244465ccfc5337c59e63c6b0)
Diffstat (limited to 'src/server/database/Database/QueryCallback.h')
-rw-r--r--src/server/database/Database/QueryCallback.h55
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
{