public static async ETTask <T> Query <T>(this DBProxyComponent self, long id, bool needCache = true) where T : ComponentWithId { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache }); return((T)dbQueryResponse.Component); }
private static async ETVoid QueryInner <T>(this DBProxyComponent self, long id, string key) where T : ComponentWithId { try { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id }); T result = (T)dbQueryResponse.Component; object[] tcss = self.TcsQueue.GetAll(key); self.TcsQueue.Remove(key); foreach (ETTaskCompletionSource <T> tcs in tcss) { tcs.SetResult(result); } } catch (Exception e) { object[] tcss = self.TcsQueue.GetAll(key); self.TcsQueue.Remove(key); foreach (ETTaskCompletionSource <T> tcs in tcss) { tcs.SetException(e); } } }