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

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

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