Beispiel #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);
        }
Beispiel #3
0
 Task IFunction.InvokeAndStripAsync(ComputedInput input,
                                    IComputed?usedBy,
                                    ComputeContext?context,
                                    CancellationToken cancellationToken)
 => InvokeAndStripAsync((TIn)input, usedBy, context, cancellationToken);
Beispiel #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);
 protected abstract IComputed?TryGetCached(ComputedInput input);
 IComputed?IFunction.TryGetCached(ComputedInput input) => TryGetCached(input);
Beispiel #10
0
 IComputed?IFunction.TryGetCached(ComputedInput input, IComputed?usedBy)
 => TryGetCached((TIn)input, null);
Beispiel #11
0
 protected abstract IComputed?TryGetCached(ComputedInput input, IComputed?usedBy);
Beispiel #12
0
 IComputed?IFunction.TryGetCached(ComputedInput input, IComputed?usedBy)
 => TryGetCached(input, usedBy);