Beispiel #1
0
        /// <summary>
        /// Adds a channel read case to the builder.  If this case wins due to successfully
        /// being able to read data from the channel, the specified action will be invoked
        /// with the read data.
        /// </summary>
        /// <typeparam name="T">Specifies the type of data in the channel.</typeparam>
        /// <param name="channel">The channel from which to read.</param>
        /// <param name="action">The synchronous action to invoke with an element read from the channel.</param>
        /// <returns>This builder.</returns>
        public CaseBuilder CaseRead <T>(ReadableChannel <T> channel, Action <T> action)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            _cases.Add(new SyncReadCase <T>(channel, action));
            return(this);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a channel read case to the builder.  If this case wins due to successfully
        /// being able to read data from the channel, the specified function will be invoked
        /// with the read data.
        /// </summary>
        /// <typeparam name="T">Specifies the type of data in the channel.</typeparam>
        /// <param name="channel">The channel from which to read.</param>
        /// <param name="func">The asynchronous function to invoke with an element read from the channel.</param>
        /// <returns>This builder.</returns>
        public CaseBuilder CaseRead <T>(ReadableChannel <T> channel, Func <T, Task> func)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            _cases.Add(new AsyncReadCase <T>(channel, func));
            return(this);
        }
Beispiel #3
0
        public static async Task <List <T> > ReadAllAsync <T>(this ReadableChannel <T> channel)
        {
            var list = new List <T>();

            while (await channel.WaitToReadAsync())
            {
                while (channel.TryRead(out var item))
                {
                    list.Add(item);
                }
            }

            // Manifest any error from channel.Completion (which should be completed now)
            await channel.Completion;

            return(list);
        }
Beispiel #4
0
 internal AsyncReadCase(ReadableChannel <T> channel, Func <T, Task> action)
 {
     _channel = channel;
     _action  = action;
 }
Beispiel #5
0
 internal SyncReadCase(ReadableChannel <T> channel, Action <T> action)
 {
     _channel = channel;
     _action  = action;
 }
Beispiel #6
0
 internal ChannelObservable(ReadableChannel <T> channel)
 {
     Debug.Assert(channel != null);
     _channel = channel;
 }
Beispiel #7
0
 internal AsyncEnumerator(ReadableChannel <T> channel, CancellationToken cancellationToken)
 {
     _channel           = channel;
     _cancellationToken = cancellationToken;
 }