public Task WaitAny() { if (_storage == null) { return(Task.Completed()); } if (!_isStorageRing) { StorageAsTask.Wait(); } var handles = new WaitHandle[StorageAsRing.Count]; int i = 0; foreach (Task task in StorageAsRing) { if (task == null) { throw new ArgumentNullException(); } if (task.IsComplete) { return(task); } if (!TaskContinuationManager.ScheduleAntecedent(task)) { task.Schedule(); } //BUG?: we need to handle completed tasks handles[i++] = task.CompletionHandle; } var index = WaitHandle.WaitAny(handles); return((Task)StorageAsRing.FindAtIndex(index) .Value); }
public void Dispose() { if (_isStorageRing && _storage != null) { StorageAsRing.Clear(); } }
public WaitList(params Task[] tasks) { if (tasks == null) { throw new ArgumentNullException("tasks"); } _storage = new Ring(); foreach (Task task in tasks) { if (task == null) { throw new ArgumentNullException("task"); } StorageAsRing.InsertTail(task); } }
public void Add(Task task) { if (task == null) { throw new ArgumentNullException(); } lock (this) { if (_storage == null) { _storage = task; } else if (!_isStorageRing) { _storage = new Ring(_storage, task); _isStorageRing = true; } else { StorageAsRing.InsertTail(task); } } }