/// <summary>
        /// Returns all the selectors for a given <paramref name="weakFingerprint"/>.
        /// </summary>
        public static async Task <Result <Selector[]> > GetAllSelectorsAsync(
            this ILevelSelectorsProvider session,
            Context context,
            Fingerprint weakFingerprint,
            CancellationToken cts)
        {
            var selectors = new List <Selector>();
            int level     = 0;

            while (true)
            {
                var levelResult = await session.GetLevelSelectorsAsync(context, weakFingerprint, cts, level);

                if (!levelResult)
                {
                    return(Result.FromError <Selector[]>(levelResult));
                }

                selectors.AddRange(levelResult.Value.Selectors);

                level++;
                if (!levelResult.Value.HasMore)
                {
                    break;
                }
            }

            return(Result.Success(selectors.ToArray()));
        }
 /// <summary>
 /// Enumerate known selectors for a given weak fingerprint.
 /// </summary>
 public static Async::System.Collections.Generic.IAsyncEnumerable <GetSelectorResult> GetSelectorsAsAsyncEnumerable(
     this ILevelSelectorsProvider session,
     Context context,
     Fingerprint weakFingerprint,
     CancellationToken cts,
     UrgencyHint urgencyHint = UrgencyHint.Nominal)
 {
     // This method is a backward compatible method that was used before the implementation was moved to use levels explicitly.
     return(AsyncEnumerable.Range(0, int.MaxValue)
            .SelectMany(level => GetLevelSelectorsEnumerableAsync(session, context, weakFingerprint, cts, level))
            .StopAfter(item => item.Succeeded && item.Value.HasMore)
            .SelectMany(ToSelectorResults));
 }
 private static Async::System.Collections.Generic.IAsyncEnumerable <Result <LevelSelectors> > GetLevelSelectorsEnumerableAsync(
     this ILevelSelectorsProvider session,
     Context context,
     Fingerprint weakFingerprint,
     CancellationToken cts,
     int level)
 {
     return(AsyncEnumerableExtensions.CreateSingleProducerTaskAsyncEnumerable <Result <LevelSelectors> >(
                async() =>
     {
         var result = await session.GetLevelSelectorsAsync(context, weakFingerprint, cts, level);
         return new[] { result };
     }));
 }