Exemple #1
0
        /// <summary>
        /// Makes <paramref name="source"/> connectable.
        /// </summary>
        /// <param name="source">The source sequence.</param>
        /// <param name="connect">Set to a <see cref="ConnectDelegate"/> that, when invoked, connects to the <paramref name="source"/>.</param>
        /// <remarks>
        /// When <paramref name="connect"/> is called, all enumerators awaiting <see cref="IAsyncEnumerator{T}.MoveNextAsync"/> will observe the same sequence.
        /// Late enumerators will experience a <see cref="AlreadyConnectedException"/>.
        /// </remarks>
        public static IAsyncEnumerable <T> Connectable <T>(this IAsyncEnumerable <T> source, out ConnectDelegate connect)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            var connectable = new ConnectableEnumerable <T>(source);

            connect = connectable.Connect;
            return(connectable);
        }
Exemple #2
0
        /// <summary>
        /// Makes <paramref name="source"/> connectable, pushing the <see cref="ConnectDelegate"/> to the stack.
        /// </summary>
        public static IAsyncEnumerable <T> Connectable <T>(this IAsyncEnumerable <T> source, Stack <ConnectDelegate> stack)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (stack == null)
            {
                throw new ArgumentNullException(nameof(stack));
            }

            var connectable = new ConnectableEnumerable <T>(source);

            stack.Push(connectable.Connect);
            return(connectable);
        }