Beispiel #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));
 }
Beispiel #2
0
 public Promise(Exception exception)
 {
     Exception    = exception;
     _hashCode    = exception.GetHashCode();
     _waitHandle  = new ManualResetEventSlim(true);
     _onCompleted = new StrongDelegateCollection(true);
 }
Beispiel #3
0
 public Promise(bool done)
 {
     Exception = null;
     _hashCode = base.GetHashCode();
     if (!done)
     {
         _waitHandle = new ManualResetEventSlim(false);
     }
 }
Beispiel #4
0
        public bool Equals(StructNeedle <T> other)
        {
            var value = other.Value;

            if (other.IsAlive)
            {
                return(Equals(value));
            }
            return(!IsAlive);
        }
Beispiel #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));
 }
Beispiel #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));
 }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #9
0
        public Promise(bool done)
        {
            Exception = null;
            _hashCode = base.GetHashCode();
            if (!done)
            {
                _waitHandle = new ManualResetEventSlim(false);
            }

            _onCompleted = new StrongDelegateCollection(true);
        }
Beispiel #10
0
 public CacheNeedle()
     : base(default(T))
 {
     _valueFactory = null;
     _waitHandle   = new StructNeedle <ManualResetEventSlim>(null);
 }
Beispiel #11
0
 public CacheNeedle(T target)
     : base(target)
 {
     _valueFactory = null;
     _waitHandle   = new StructNeedle <ManualResetEventSlim>(null);
 }
Beispiel #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));
 }
Beispiel #13
0
 public bool Equals(StructNeedle <T> other)
 {
     return(EqualsExtracted(this, other));
 }
Beispiel #14
0
 public Promise(Exception exception)
 {
     Exception   = exception;
     _hashCode   = exception.GetHashCode();
     _waitHandle = new ManualResetEventSlim(true);
 }