Beispiel #1
0
        internal static bool TryUseExisting <T>(this IComputed <T>?existing, ComputeContext context, IComputed?usedBy)
        {
            var callOptions = context.CallOptions;
            var useExisting = (callOptions & CallOptions.TryGetExisting) != 0;

            if (existing == null)
            {
                return(useExisting);
            }
            if (!(useExisting || existing.IsConsistent()))
            {
                return(false);
            }

            context.TryCapture(existing);
            var invalidate = (callOptions & CallOptions.Invalidate) == CallOptions.Invalidate;

            if (invalidate)
            {
                existing.Invalidate();
                return(true);
            }
            if (!useExisting)
            {
                ((IComputedImpl?)usedBy)?.AddUsed((IComputedImpl)existing !);
            }
            ((IComputedImpl?)existing)?.RenewTimeouts();
            return(true);
        }
Beispiel #2
0
        internal static bool TryUseExisting <T>(this IComputed <T>?existing, ComputeContext context, IComputed?usedBy)
        {
            var callOptions = context.CallOptions;
            var useExisting = (callOptions & CallOptions.TryGetExisting) != 0;

            if (existing == null)
            {
                return(useExisting);
            }
            useExisting |= existing.IsConsistent();
            if (!useExisting)
            {
                return(false);
            }

            if ((callOptions & CallOptions.Capture) != 0)
            {
                Interlocked.Exchange(ref context.CapturedComputed, existing);
            }
            if ((callOptions & CallOptions.Invalidate) == CallOptions.Invalidate)
            {
                existing.Invalidate();
                return(true);
            }
            ((IComputedImpl?)usedBy)?.AddUsed((IComputedImpl)existing !);
            ((IComputedImpl?)existing)?.RenewTimeouts();
            return(true);
        }
Beispiel #3
0
 internal static bool TryUseExistingFromUse <T>(this IComputed <T>?existing, ComputeContext context, IComputed?usedBy)
 {
     if (existing == null || !existing.IsConsistent())
     {
         return(false);
     }
     context.TryCapture(existing);
     ((IComputedImpl?)usedBy)?.AddUsed((IComputedImpl)existing !);
     ((IComputedImpl?)existing)?.RenewTimeouts();
     return(true);
 }