public FABChannelGroupCompletionSource(IFABChannelGroup sgroup, Dictionary <IFABChannel, Task> futures /*, IEventExecutor executor*/, object state) : base(state) { Contract.Requires(sgroup != null); Contract.Requires(futures != null); this.groub = sgroup; this.futures = new Dictionary <IFABChannel, Task>(); foreach (KeyValuePair <IFABChannel, Task> pair in futures) { this.futures.Add(pair.Key, pair.Value); pair.Value.ContinueWith(x => { bool success = x.Status == TaskStatus.RanToCompletion; bool callSetDone; lock (this) { if (success) { this.successCount++; } else { this.failureCount++; } callSetDone = this.successCount + this.failureCount == this.futures.Count; Contract.Assert(this.successCount + this.failureCount <= this.futures.Count); } if (callSetDone) { if (this.failureCount > 0) { var failed = new List <KeyValuePair <IFABChannel, Exception> >(); foreach (KeyValuePair <IFABChannel, Task> ft in this.futures) { IFABChannel c = ft.Key; Task f = ft.Value; if (f.IsFaulted || f.IsCanceled) { if (f.Exception != null) { failed.Add(new KeyValuePair <IFABChannel, Exception>(c, f.Exception.InnerException)); } } } this.TrySetException(new FABChannelGroupException(failed)); } else { this.TrySetResult(0); } } }); } // Done on arrival? if (futures.Count == 0) { this.TrySetResult(0); } }
public int CompareTo(IFABChannelGroup other) { return(this.CompareTo(other)); }
public FABChannelGroupCompletionSource(IFABChannelGroup sgroup, Dictionary <IFABChannel, Task> futures /*, IEventExecutor executor*/) : this(sgroup, futures /*,executor*/, null) { }