Пример #1
0
        public IComputed?TryGet(ComputedInput key)
        {
            var random = Randomize(key.HashCode);

            OnOperation(random);
            if (_storage.TryGetValue(key, out var entry))
            {
                var value = entry.Computed;
                if (value != null)
                {
                    value.Touch();
                    return(value);
                }

                var handle = entry.Handle;
                value = (IComputed?)handle.Target;
                if (value != null)
                {
                    value.Touch();
                    _storage.TryUpdate(key, new Entry(value, handle), entry);
                    return(value);
                }
                if (_storage.TryRemove(key, entry))
                {
                    _gcHandlePool.Release(handle, random);
                }
            }
            return(null);
        }
Пример #2
0
        public virtual IComputed?TryGet(ComputedInput key)
        {
            var random = Randomize(key.HashCode);

            OnOperation(random);
            if (_storage.TryGetValue(key, out var handle))
            {
                var value = (IComputed?)handle.Target;
                if (value != null)
                {
                    return(value);
                }
                if (_storage.TryRemove(key, handle))
                {
                    _gcHandlePool.Release(handle, random);
                }
            }
            return(null);
        }
Пример #3
0
 Task IFunction.InvokeAndStripAsync(ComputedInput input,
                                    IComputed?usedBy,
                                    ComputeContext?context,
                                    CancellationToken cancellationToken)
 => InvokeAndStripAsync((TIn)input, usedBy, context, cancellationToken);
Пример #4
0
 async Task <IComputed> IFunction.InvokeAsync(ComputedInput input,
                                              IComputed?usedBy,
                                              ComputeContext?context,
                                              CancellationToken cancellationToken)
 => await InvokeAsync((TIn)input, usedBy, context, cancellationToken).ConfigureAwait(false);
Пример #5
0
 public override bool Equals(ComputedInput other)
 => ReferenceEquals(this, other);
Пример #6
0
 protected abstract Task InvokeAndStripAsync(
     ComputedInput input, IComputed?usedBy, ComputeContext?context,
     CancellationToken cancellationToken);
Пример #7
0
        // IFunction

        Task <IComputed> IFunction.InvokeAsync(
            ComputedInput input, IComputed?usedBy, ComputeContext?context,
            CancellationToken cancellationToken) =>
        InvokeAsync(input, usedBy, context, cancellationToken);
Пример #8
0
 protected abstract IComputed?TryGetCached(ComputedInput input);
Пример #9
0
 IComputed?IFunction.TryGetCached(ComputedInput input) => TryGetCached(input);
Пример #10
0
 IComputed?IFunction.TryGetCached(ComputedInput input, IComputed?usedBy)
 => TryGetCached((TIn)input, null);
Пример #11
0
 protected abstract IComputed?TryGetCached(ComputedInput input, IComputed?usedBy);
Пример #12
0
 IComputed?IFunction.TryGetCached(ComputedInput input, IComputed?usedBy)
 => TryGetCached(input, usedBy);