Exemple #1
0
 public CacheNeedle(Func <T> valueFactory, T target, bool trackResurrection, bool cacheExceptions)
     : base(target, trackResurrection)
 {
     if (valueFactory == null)
     {
         throw new ArgumentNullException("valueFactory");
     }
     _valueFactory = valueFactory;
     if (cacheExceptions)
     {
         _valueFactory = () =>
         {
             try
             {
                 return(valueFactory.Invoke());
             }
             catch (Exception exc)
             {
                 _valueFactory = FuncHelper.GetThrowFunc <T>(exc);
                 throw;
             }
         };
     }
     _waitHandle = new StructNeedle <ManualResetEventSlim>(new ManualResetEventSlim(false));
 }
Exemple #2
0
 public Promise(Exception exception)
 {
     Exception    = exception;
     _hashCode    = exception.GetHashCode();
     _waitHandle  = new ManualResetEventSlim(true);
     _onCompleted = new StrongDelegateCollection(true);
 }
Exemple #3
0
 public Promise(bool done)
 {
     Exception = null;
     _hashCode = base.GetHashCode();
     if (!done)
     {
         _waitHandle = new ManualResetEventSlim(false);
     }
 }
Exemple #4
0
        public bool Equals(StructNeedle <T> other)
        {
            var value = other.Value;

            if (other.IsAlive)
            {
                return(Equals(value));
            }
            return(!IsAlive);
        }
Exemple #5
0
 public CacheNeedle(Func <T> valueFactory, T target, bool trackResurrection)
     : base(target, trackResurrection)
 {
     if (valueFactory == null)
     {
         throw new ArgumentNullException("valueFactory");
     }
     _valueFactory = valueFactory;
     _waitHandle   = new StructNeedle <ManualResetEventSlim>(new ManualResetEventSlim(false));
 }
Exemple #6
0
 public CacheNeedle(Func <T> valueFactory)
     : base(default(T))
 {
     if (valueFactory == null)
     {
         throw new ArgumentNullException("valueFactory");
     }
     _valueFactory = valueFactory;
     _waitHandle   = new StructNeedle <ManualResetEventSlim>(new ManualResetEventSlim(false));
 }
Exemple #7
0
        public bool Equals(StructNeedle <T> other)
        {
            var leftValue = Value;

            if (IsAlive)
            {
                var rightValue = other.Value;
                return(other.IsAlive && EqualityComparer <T> .Default.Equals(leftValue, rightValue));
            }
            return(!other.IsAlive);
        }
Exemple #8
0
        private static bool EqualsExtracted(StructNeedle <T> left, StructNeedle <T> right)
        {
            var leftValue = left.Value;

            if (left.IsAlive)
            {
                var rightValue = right.Value;
                return(right.IsAlive && EqualityComparer <T> .Default.Equals(leftValue, rightValue));
            }
            return(!right.IsAlive);
        }
Exemple #9
0
        public Promise(bool done)
        {
            Exception = null;
            _hashCode = base.GetHashCode();
            if (!done)
            {
                _waitHandle = new ManualResetEventSlim(false);
            }

            _onCompleted = new StrongDelegateCollection(true);
        }
Exemple #10
0
 public CacheNeedle()
     : base(default(T))
 {
     _valueFactory = null;
     _waitHandle   = new StructNeedle <ManualResetEventSlim>(null);
 }
Exemple #11
0
 public CacheNeedle(T target)
     : base(target)
 {
     _valueFactory = null;
     _waitHandle   = new StructNeedle <ManualResetEventSlim>(null);
 }
Exemple #12
0
 public CacheNeedle(Func <T> valueFactory, T target)
     : base(target)
 {
     _valueFactory = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory));
     _waitHandle   = new StructNeedle <ManualResetEventSlim>(new ManualResetEventSlim(false));
 }
Exemple #13
0
 public bool Equals(StructNeedle <T> other)
 {
     return(EqualsExtracted(this, other));
 }
Exemple #14
0
 public Promise(Exception exception)
 {
     Exception   = exception;
     _hashCode   = exception.GetHashCode();
     _waitHandle = new ManualResetEventSlim(true);
 }