/// <summary> /// Read from the channel set in a probing manner /// </summary> /// <param name="self">The channels to read from</param> /// <param name="channel">The channel written to</param> /// <param name="value">The value to write into the channel</param> /// <typeparam name="T">The channel data type parameter.</typeparam> public static bool TryWriteToAny <T>(this MultiChannelSetWrite <T> self, T value, out IWriteChannel <T> channel) { var res = self.WriteToAnyAsync(value, Timeout.Immediate).WaitForTask(); if (res.IsFaulted || res.IsCanceled) { channel = res.Result; return(true); } else { channel = null; return(false); } }
/// <summary> /// Write to the channel set in a blocking manner /// </summary> /// <param name="self">The channels to read from</param> /// <param name="timeout">The maximum time to wait for a slot</param> /// <param name="value">The value to write into the channel</param> /// <typeparam name="T">The channel data type parameter.</typeparam> public static IWriteChannel <T> WriteToAny <T>(this MultiChannelSetWrite <T> self, T value, TimeSpan timeout) { try { return(self.WriteToAnyAsync(value, timeout).WaitForTask().Result); } catch (AggregateException aex) { if (aex.Flatten().InnerExceptions.Count == 1) { throw aex.InnerException; } throw; } }