public Task <List <Disposer> > GetBatch(string collectionName, List <long> idList)
        {
            List <Disposer> disposers    = new List <Disposer>();
            bool            isAllInCache = true;

            foreach (long id in idList)
            {
                Disposer entity = this.GetFromCache(collectionName, id);
                if (entity == null)
                {
                    isAllInCache = false;
                    break;
                }
                disposers.Add(entity);
            }

            if (isAllInCache)
            {
                return(Task.FromResult(disposers));
            }

            TaskCompletionSource <List <Disposer> > tcs = new TaskCompletionSource <List <Disposer> >();
            DBQueryBatchTask dbQueryBatchTask           = EntityFactory.Create <DBQueryBatchTask, List <long>, string, TaskCompletionSource <List <Disposer> > >(idList, collectionName, tcs);

            this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);

            return(tcs.Task);
        }
Beispiel #2
0
        public Task <List <Entity> > GetBatch(string collectionName, List <long> idList)
        {
            List <Entity> entitys      = new List <Entity>();
            bool          isAllInCache = true;

            foreach (long id in idList)
            {
                Entity entity = this.GetFromCache(collectionName, id);
                if (entity == null)
                {
                    isAllInCache = false;
                    break;
                }
                entitys.Add(entity);
            }

            if (isAllInCache)
            {
                return(Task.FromResult(entitys));
            }

            TaskCompletionSource <List <Entity> > tcs = new TaskCompletionSource <List <Entity> >();
            DBQueryBatchTask dbQueryBatchTask         = new DBQueryBatchTask(idList, collectionName, tcs);

            this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);

            return(tcs.Task);
        }
 public override void Awake(DBQueryBatchTask self, List <long> idList, string collectionName, TaskCompletionSource <List <Component> > tcs)
 {
     self.IdList         = idList;
     self.CollectionName = collectionName;
     self.Tcs            = tcs;
 }