Exemple #1
0
        /// <summary>
        /// Retrieves a list of scopes using their name.
        /// </summary>
        /// <param name="names">The names associated with the scopes.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
        /// <returns>
        /// A <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
        /// whose result returns the scopes corresponding to the specified names.
        /// </returns>
        public ValueTask <ImmutableArray <TScope> > FindByNamesAsync(ImmutableArray <string> names, CancellationToken cancellationToken)
        {
            if (names.IsDefaultOrEmpty)
            {
                return(new ValueTask <ImmutableArray <TScope> >(ImmutableArray.Create <TScope>()));
            }

            if (names.Any(name => string.IsNullOrEmpty(name)))
            {
                throw new ArgumentException("Scope names cannot be null or empty.", nameof(names));
            }

            // Note: this method is only partially cached.

            async Task <ImmutableArray <TScope> > ExecuteAsync()
            {
                var scopes = await _store.FindByNamesAsync(names, cancellationToken);

                foreach (var scope in scopes)
                {
                    await AddAsync(scope, cancellationToken);
                }

                return(scopes);
            }

            return(new ValueTask <ImmutableArray <TScope> >(ExecuteAsync()));
        }
Exemple #2
0
        /// <summary>
        /// Retrieves a list of scopes using their name.
        /// </summary>
        /// <param name="names">The names associated with the scopes.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
        /// <returns>The scopes corresponding to the specified names.</returns>
        public IAsyncEnumerable <TScope> FindByNamesAsync(ImmutableArray <string> names, CancellationToken cancellationToken)
        {
            if (names.IsDefaultOrEmpty)
            {
                return(AsyncEnumerable.Empty <TScope>());
            }

            if (names.Any(name => string.IsNullOrEmpty(name)))
            {
                throw new ArgumentException("Scope names cannot be null or empty.", nameof(names));
            }

            // Note: this method is only partially cached.

            async IAsyncEnumerable <TScope> ExecuteAsync()
            {
                await foreach (var scope in _store.FindByNamesAsync(names, cancellationToken))
                {
                    await AddAsync(scope, cancellationToken);

                    yield return(scope);
                }
            }

            return(ExecuteAsync());
        }