Example #1
0
        public override void SetResult(T result, bool isCompleted = true)
        {
            if (isCompleted)
            {
                block?.Dispose();
            }

            base.SetResult(result, isCompleted);
        }
Example #2
0
        /// <summary>
        /// 重置状态
        /// </summary>
        public void Reset()
        {
            _locker.EnterWriteLock();

            _isValueCreated = false;
            _block.Dispose();
            _value = default(T);

            _locker.ExitWriteLock();
        }
Example #3
0
        private void timeoutCallback(object state)
        {
            if (!IsCompleted)
            {
                try
                {
                    _onTimeoutCallback?.Invoke(this, EventArgs.Empty);
                }
                catch (Exception)
                {
                }
                finally
                {
                    block.Stop();
                    block.Dispose();

                    if (_whenTimeoutThrowException)
                    {
                        base.SetError(new TimeoutException());
                    }
                    else
                    {
                        IsCompleted = true;
                    }
                }
            }
        }