コード例 #1
0
                public async ValueTask <bool> MoveNextAsync()
                {
                    Verify.NotDisposed(!this.disposed, this);

                    // Consume one locally cached value, if we have one.
                    if (this.localCachedValues.Length > 0)
                    {
                        if (this.moveNextCalled)
                        {
                            this.localCachedValues.AdvanceTo(this.localCachedValues.AsReadOnlySequence.GetPosition(1));
                        }
                        else
                        {
                            // Don't consume one the first time we're called if we have an initial set of values.
                            this.moveNextCalled = true;
                            return(true);
                        }
                    }

                    this.moveNextCalled = true;

                    if (this.localCachedValues.Length == 0 && !this.generatorReportsFinished)
                    {
                        // Fetch more values
                        try
                        {
                            EnumeratorResults <T> results = await this.owner.jsonRpc.InvokeWithCancellationAsync <EnumeratorResults <T> >(NextMethodName, this.nextOrDisposeArguments, this.cancellationToken).ConfigureAwait(false);

                            if (!results.Finished && results.Values?.Count == 0)
                            {
                                throw new UnexpectedEmptyEnumerableResponseException("The RPC server responded with an empty list of additional values for an incomplete list.");
                            }

                            if (results.Values is not null)
                            {
                                Write(this.localCachedValues, results.Values);
                            }

                            this.generatorReportsFinished = results.Finished;
                        }
                        catch (RemoteInvocationException ex)
                        {
                            // Avoid spending a message asking the server to dispose of the marshalled enumerator since they threw an exception at us.
                            this.generatorReportsFinished = true;

                            if (ex.ErrorCode == (int)JsonRpcErrorCode.NoMarshaledObjectFound)
                            {
                                throw new InvalidOperationException(ex.Message, ex);
                            }

                            throw;
                        }
                    }

                    return(this.localCachedValues.Length > 0);
                }
                public async ValueTask <bool> MoveNextAsync()
                {
                    Verify.NotDisposed(!this.disposed, this);

                    // Consume one locally cached value, if we have one.
                    if (this.localCachedValues.Length > 0)
                    {
                        if (this.moveNextCalled)
                        {
                            this.localCachedValues.AdvanceTo(this.localCachedValues.AsReadOnlySequence.GetPosition(1));
                        }
                        else
                        {
                            // Don't consume one the first time we're called if we have an initial set of values.
                            this.moveNextCalled = true;
                            return(true);
                        }
                    }

                    this.moveNextCalled = true;

                    if (this.localCachedValues.Length == 0 && !this.generatorReportsFinished)
                    {
                        // Fetch more values
                        try
                        {
                            EnumeratorResults <T> results = await this.owner.jsonRpc.InvokeWithCancellationAsync <EnumeratorResults <T> >(NextMethodName, this.nextOrDisposeArguments, this.cancellationToken).ConfigureAwait(false);

                            if (results.Values != null)
                            {
                                Write(this.localCachedValues, results.Values);
                            }

                            this.generatorReportsFinished = results.Finished;
                        }
                        catch (RemoteInvocationException ex) when(ex.ErrorCode == (int)JsonRpcErrorCode.NoMarshaledObjectFound)
                        {
                            throw new InvalidOperationException(ex.Message, ex);
                        }
                    }

                    return(this.localCachedValues.Length > 0);
                }