Esempio n. 1
0
        public ETTask <List <ComponentWithId> > GetBatch(string collectionName, List <long> idList)
        {
            List <ComponentWithId> components = new List <ComponentWithId>();
            bool isAllInCache = true;

            foreach (long id in idList)
            {
                ComponentWithId component = this.GetFromCache(collectionName, id);
                if (component == null)
                {
                    isAllInCache = false;
                    break;
                }
                components.Add(component);
            }

            if (isAllInCache)
            {
                return(ETTask.FromResult(components));
            }

            ETTaskCompletionSource <List <ComponentWithId> > tcs = new ETTaskCompletionSource <List <ComponentWithId> >();
            DBQueryBatchTask dbQueryBatchTask = ComponentFactory.Create <DBQueryBatchTask, List <long>, string, ETTaskCompletionSource <List <ComponentWithId> > >(idList, collectionName, tcs);

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

            return(tcs.Task);
        }
Esempio n. 2
0
            static CanceledETTaskCache()
            {
                ETTaskCompletionSource tcs = new ETTaskCompletionSource();

                tcs.TrySetCanceled();
                Task = tcs.Task;
            }
Esempio n. 3
0
            static CanceledETTaskCache()
            {
                var promise = new ETTaskCompletionSource <T>();

                promise.TrySetCanceled();
                Task = new ETTask <T>(promise);
            }
Esempio n. 4
0
        public ETTask <bool> MoveToAsync(Vector3 dest, float speedValue, CancellationToken cancellationToken)
        {
            if ((dest - this.GetParent <Unit>().Position).magnitude < 0.1f)
            {
                this.IsArrived = true;
                return(ETTask.FromResult(false));
            }

            if ((dest - this.Dest).magnitude < 0.1f)
            {
                return(ETTask.FromResult(false));
            }

            this.moveTcs   = new ETTaskCompletionSource <bool>();
            this.IsArrived = false;
            Vector3 spd = dest - this.GetParent <Unit>().Position;

            spd        = spd.normalized * speedValue;
            this.Speed = spd;
            this.Dest  = dest;

            cancellationToken.Register(() => this.moveTcs = null);

            return(this.moveTcs.Task);
        }
Esempio n. 5
0
        private void Create()
        {
            var f = Interlocked.Exchange(ref factory, null);

            if (f != null)
            {
                value = f();
            }
        }
Esempio n. 6
0
 public ETTask <Session> Get(AppType appType)
 {
     foreach (KeyValuePair <IPEndPoint, int> kv in serverIPs)
     {
         if (AppTypeHelper.Is(kv.Value, appType))
         {
             return(Get(kv.Key));
         }
     }
     return(ETTask.FromResult <Session>(null));
 }
Esempio n. 7
0
        public ETTask <DBTask> Get()
        {
            if (this.queue.Count > 0)
            {
                DBTask task = this.queue.Dequeue();
                return(ETTask.FromResult(task));
            }

            ETTaskCompletionSource <DBTask> t = new ETTaskCompletionSource <DBTask>();

            this.tcs = t;
            return(t.Task);
        }
Esempio n. 8
0
        public ETTask <long> GetAsync(long key)
        {
            if (!this.lockDict.ContainsKey(key))
            {
                this.locations.TryGetValue(key, out long instanceId);
                Log.Info($"location get key: {key} {instanceId}");
                return(ETTask.FromResult(instanceId));
            }

            LocationQueryTask task = ComponentFactory.CreateWithParent <LocationQueryTask, long>(this, key);

            this.AddTask(key, task);
            return(task.Task);
        }
Esempio n. 9
0
        public ETTask <ComponentWithId> Get(string collectionName, long id)
        {
            ComponentWithId component = GetFromCache(collectionName, id);

            if (component != null)
            {
                return(ETTask.FromResult(component));
            }

            ETTaskCompletionSource <ComponentWithId> tcs = new ETTaskCompletionSource <ComponentWithId>();
            DBQueryTask dbQueryTask = ComponentFactory.CreateWithId <DBQueryTask, string, ETTaskCompletionSource <ComponentWithId> >(id, collectionName, tcs);

            this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);

            return(tcs.Task);
        }
Esempio n. 10
0
        public ETTask <CoroutineLock> Wait(CoroutineLockType coroutineLockType, long key)
        {
            CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType];

            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
            {
                queue = EntityFactory.Create <CoroutineLockQueue>(this.Domain);
                coroutineLockQueueType.Add(key, queue);

                return(ETTask.FromResult(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key)));
            }

            ETTaskCompletionSource <CoroutineLock> tcs = new ETTaskCompletionSource <CoroutineLock>();

            queue.Enqueue(tcs);
            return(tcs.Task);
        }
Esempio n. 11
0
 //[DebuggerHidden]
 public Awaiter(ETTask task)
 {
     this.task = task;
 }
Esempio n. 12
0
 public static (ETTask, CancellationTokenRegistration) ToETTask(this CancellationToken cts)
 {
     if (cts.IsCancellationRequested)
     {
         return(ETTask.FromCanceled(cts), default);