예제 #1
0
        /// <summary>
        ///
        /// </summary>
        public void GetResult()
        {
            if (Result.Id != Id)
            {
                throw new InvalidTaskReuseException("A mismatch was detected between the ResuableTask and its Result source. This typically means the ReusableTask was awaited twice concurrently. If you need to do this, convert the ReusableTask to a Task before awaiting.");
            }

            var exception = Result.Exception;

            if (Result.Cacheable)
            {
                ReusableTaskMethodBuilder.Release(Result);
            }

            if (exception != null)
            {
                ExceptionDispatchInfo.Capture(exception).Throw();
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public T GetResult()
        {
            if (Task.ResultHolder.Id != Id)
            {
                throw new InvalidTaskReuseException("A mismatch was detected between the ResuableTask and its Result source. This typically means the ReusableTask was awaited twice concurrently. If you need to do this, convert the ReusableTask to a Task before awaiting.");
            }

            var result    = Task.ResultHolder == ReusableTask <T> .SyncCompleted ? Task.Result : Task.ResultHolder.GetResult();
            var exception = Task.ResultHolder?.Exception;

            if (Task.ResultHolder != ReusableTask <T> .SyncCompleted)
            {
                ReusableTaskMethodBuilder <T> .Release(Task.ResultHolder);
            }

            if (exception != null)
            {
                ExceptionDispatchInfo.Capture(exception).Throw();
            }
            return(result);
        }