示例#1
0
        /// <summary>
        /// Read from 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 value</param>
        /// <returns>The value read from a channel</returns>
        /// <typeparam name="T">The channel data type parameter.</typeparam>
        public static MultisetResult <T> ReadFromAny <T>(this MultiChannelSetRead <T> self, TimeSpan timeout)
        {
            try
            {
                return(self.ReadFromAnyAsync(timeout).WaitForTask().Result);
            }
            catch (AggregateException aex)
            {
                if (aex.Flatten().InnerExceptions.Count == 1)
                {
                    throw aex.InnerException;
                }

                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Read from the channel set in a probing manner
        /// </summary>
        /// <param name="self">The channels to read from</param>
        /// <param name="value">The value that was read</param>
        /// <param name="channel">The channel read from</param>
        /// <typeparam name="T">The channel data type parameter.</typeparam>
        /// <returns>The value read from a channel</returns>
        public static bool TryReadFromAny <T>(this MultiChannelSetRead <T> self, out T value, out IReadChannel <T> channel)
        {
            var res = self.ReadFromAnyAsync(Timeout.Immediate).WaitForTask();

            if (res.IsFaulted || res.IsCanceled)
            {
                channel = null;
                value   = default(T);
                return(false);
            }
            else
            {
                channel = res.Result.Channel;
                value   = res.Result.Value;
                return(true);
            }
        }
示例#3
0
        /// <summary>
        /// Read from the channel set in a blocking manner
        /// </summary>
        /// <param name="self">The channels to read from</param>
        /// <param name="channel">The channel written to</param>
        /// <param name="timeout">The maximum time to wait for a value</param>
        /// <typeparam name="T">The channel data type parameter.</typeparam>
        /// <returns>The value read from a channel</returns>
        public static T ReadFromAny <T>(this MultiChannelSetRead <T> self, out IReadChannel <T> channel, TimeSpan timeout)
        {
            try
            {
                var res = self.ReadFromAnyAsync(timeout).WaitForTask().Result;
                channel = res.Channel;
                return(res.Value);
            }
            catch (AggregateException aex)
            {
                if (aex.Flatten().InnerExceptions.Count == 1)
                {
                    throw aex.InnerException;
                }

                throw;
            }
        }
示例#4
0
 /// <summary>
 /// Invokes the retire method on all channels in the set
 /// </summary>
 /// <param name="self">The channels to retire</param>
 /// <param name="immediate">A value indicating if the retire is performed immediately.</param>
 /// <typeparam name="T">The channel data type parameter.</typeparam>
 public static void Retire <T>(this MultiChannelSetRead <T> self, bool immediate = false)
 {
     self.RetireAsync(immediate).WaitForTaskOrThrow();
 }
示例#5
0
        /// <summary>
        /// Read from the channel set in a probing manner
        /// </summary>
        /// <param name="self">The channels to read from</param>
        /// <param name="value">The value read</param>
        /// <typeparam name="T">The channel data type parameter.</typeparam>
        /// <returns>The value read from a channel</returns>
        public static bool TryReadFromAny <T>(this MultiChannelSetRead <T> self, out T value)
        {
            IReadChannel <T> dummy;

            return(TryReadFromAny <T>(self, out value, out dummy));
        }