Beispiel #1
0
        public async IAsyncEnumerator <IQueryResult> GetAsyncEnumerator(
            CancellationToken cancellationToken = default)
        {
            try
            {
                IOperationContext context = _operationContextOwner.OperationContext;

                while (context.Execution.DeferredTaskBacklog.TryTake(
                           out IDeferredExecutionTask? deferredTask))
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    context.Result.Clear();
                    context.Execution.Reset();

                    yield return(await deferredTask.ExecuteAsync(context).ConfigureAwait(false));
                }
            }
            finally
            {
                _operationContextOwner.Dispose();
            }
        }
Beispiel #2
0
        public async IAsyncEnumerator <IQueryResult> GetAsyncEnumerator(
            CancellationToken cancellationToken = default)
        {
            try
            {
                IOperationContext context = _operationContextOwner.OperationContext;

                while (context.Scheduler.DeferredWork.TryTake(
                           out IDeferredExecutionTask? deferredTask))
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    // we ensure that the previous results are cleared.
                    context.ClearResult();

                    // next we execute the deferred task.
                    var result = await deferredTask.ExecuteAsync(context).ConfigureAwait(false);

                    // if we get a result we will yield it to the consumer of the result stream.
                    if (result is not null)
                    {
                        yield return(result);
                    }

                    // if null is returned and there are no more deferred tasks we will
                    // yield a termination result which signals to the consumer that
                    // no more results will follow.
                    else if (!context.Scheduler.DeferredWork.HasWork)
                    {
                        yield return(context.ClearResult().TrySetNext(true).BuildResult());
                    }
                }
            }
            finally
            {
                _operationContextOwner.Dispose();
            }
        }