コード例 #1
0
        /// <summary>
        /// Returns all the selectors for a given <paramref name="weakFingerprint"/>.
        /// </summary>
        public static async Task <Result <Selector[]> > GetAllSelectorsAsync(
            this IReadOnlyMemoizationSessionWithLevelSelectors 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()));
        }
コード例 #2
0
 /// <summary>
 /// Enumerate known selectors for a given weak fingerprint.
 /// </summary>
 public static IAsyncEnumerable <GetSelectorResult> GetSelectorsAsAsyncEnumerable(
     this IReadOnlyMemoizationSessionWithLevelSelectors 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));
 }
コード例 #3
0
 private static IAsyncEnumerable <Result <LevelSelectors> > GetLevelSelectorsEnumerableAsync(
     this IReadOnlyMemoizationSessionWithLevelSelectors 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 };
     }));
 }