示例#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);
        }
        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);
 public override bool Equals(ComputedInput other)
 => ReferenceEquals(this, other);
 protected abstract Task InvokeAndStripAsync(
     ComputedInput input, IComputed?usedBy, ComputeContext?context,
     CancellationToken cancellationToken);
        // 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);