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); }
static CanceledETTaskCache() { ETTaskCompletionSource tcs = new ETTaskCompletionSource(); tcs.TrySetCanceled(); Task = tcs.Task; }
static CanceledETTaskCache() { var promise = new ETTaskCompletionSource <T>(); promise.TrySetCanceled(); Task = new ETTask <T>(promise); }
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); }
private void Create() { var f = Interlocked.Exchange(ref factory, null); if (f != null) { value = f(); } }
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)); }
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); }
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); }
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); }
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); }
//[DebuggerHidden] public Awaiter(ETTask task) { this.task = task; }
public static (ETTask, CancellationTokenRegistration) ToETTask(this CancellationToken cts) { if (cts.IsCancellationRequested) { return(ETTask.FromCanceled(cts), default);