コード例 #1
0
#pragma warning disable VSTHRD200 // Use "Async" suffix in names of methods that return an awaitable type.
        /// <summary>
        /// Decorates an <see cref="IAsyncEnumerable{T}"/> with settings that customize how StreamJsonRpc will send its items to the remote party.
        /// </summary>
        /// <typeparam name="T">The type of element enumerated by the sequence.</typeparam>
        /// <param name="enumerable">The enumerable to be decorated.</param>
        /// <param name="settings">The settings to associate with this enumerable.</param>
        /// <returns>The decorated enumerable instance.</returns>
        public static IAsyncEnumerable <T> WithJsonRpcSettings <T>(this IAsyncEnumerable <T> enumerable, JsonRpcEnumerableSettings?settings)
        {
            Requires.NotNull(enumerable, nameof(enumerable));

            if (settings == null)
            {
                return(enumerable);
            }

            RpcEnumerable <T> rpcEnumerable = GetRpcEnumerable(enumerable);

            rpcEnumerable.Settings = settings;
            return(rpcEnumerable);
        }
コード例 #2
0
        /// <summary>
        /// Preloads an <see cref="IAsyncEnumerable{T}"/> with a cache of pre-enumerated items for inclusion in the initial transmission
        /// of the enumerable over an RPC channel.
        /// </summary>
        /// <typeparam name="T">The type of item in the collection.</typeparam>
        /// <param name="enumerable">The sequence to pre-fetch items from.</param>
        /// <param name="count">The number of items to pre-fetch. If this value is larger than the number of elements in the enumerable, all values will be pre-fetched.</param>
        /// <param name="cancellationToken">A cancellation token.</param>
        /// <returns>A decorated <see cref="IAsyncEnumerable{T}"/> object that is specially prepared for processing by JSON-RPC with the preloaded values.</returns>
        public static async ValueTask <IAsyncEnumerable <T> > WithPrefetchAsync <T>(this IAsyncEnumerable <T> enumerable, int count, CancellationToken cancellationToken = default)
        {
            Requires.NotNull(enumerable, nameof(enumerable));

            if (count == 0)
            {
                return(enumerable);
            }

            RpcEnumerable <T> rpcEnumerable = GetRpcEnumerable(enumerable);
            await rpcEnumerable.PrefetchAsync(count, cancellationToken).ConfigureAwait(false);

            return(rpcEnumerable);
        }