Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected internal ClientResult(T value, System.ClientModel.Primitives.PipelineR
public virtual T Value { get { throw null; } }
public static implicit operator T (System.ClientModel.ClientResult<T> result) { throw null; }
}
public abstract partial class StreamingClientResult<T> : System.ClientModel.ClientResult, System.Collections.Generic.IAsyncEnumerable<T>
{
protected internal StreamingClientResult(System.ClientModel.Primitives.PipelineResponse response) : base (default(System.ClientModel.Primitives.PipelineResponse)) { }
public abstract System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
}
}
namespace System.ClientModel.Primitives
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected internal ClientResult(T value, System.ClientModel.Primitives.PipelineR
public virtual T Value { get { throw null; } }
public static implicit operator T (System.ClientModel.ClientResult<T> result) { throw null; }
}
public abstract partial class StreamingClientResult<T> : System.ClientModel.ClientResult, System.Collections.Generic.IAsyncEnumerable<T>
{
protected internal StreamingClientResult(System.ClientModel.Primitives.PipelineResponse response) : base (default(System.ClientModel.Primitives.PipelineResponse)) { }
public abstract System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
}
}
namespace System.ClientModel.Primitives
{
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/System.ClientModel/src/Convenience/ClientResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,8 @@ public static ClientResult<T> FromValue<T>(T value, PipelineResponse response)
public static ClientResult<T?> FromOptionalValue<T>(T? value, PipelineResponse response)
=> new ClientResult<T?>(value, response);

//public static StreamingClientResult<T> FromStreamingValue<T>(T value, PipelineResponse response)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering this, but I don't think we can provide it without a non-abstract implementation in ClientModel. It would be the responsibility of the client's concrete subtype to provide such a factory method.

// => new StreamingClientResult<T>(response);

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading;

namespace System.ClientModel;

#pragma warning disable CS1591 // public XML comments
public abstract class StreamingClientResult<T> : ClientResult, IAsyncEnumerable<T>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing this does is abstractly implement the IAsyncEnumerable<T> interface, and provide a protected constructor that calls through to the base constructor.

We still have an open question of whether this should implement IDisposable to make it easy to dispose the response content stream by putting this result in a using block, but I'm interested to first investigate how hard it is to use the IAsyncDisposable interface implementation in the IAsyncEnumerator returned from GetAsyncEnumerator.

{
protected internal StreamingClientResult(PipelineResponse response) : base(response)
{
}

public abstract IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default);
}
#pragma warning restore CS1591 // public XML comments