-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move async collection to core (#7038)
- Loading branch information
Showing
6 changed files
with
181 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Threading; | ||
|
||
namespace Azure | ||
{ | ||
/// <summary> | ||
/// A collection of values that may take multiple service requests to | ||
/// iterate over. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the values.</typeparam> | ||
public abstract class AsyncCollection<T> : IAsyncEnumerable<Response<T>> | ||
{ | ||
/// <summary> | ||
/// Gets a <see cref="CancellationToken"/> used for requests made while | ||
/// enumerating asynchronously. | ||
/// </summary> | ||
protected virtual CancellationToken CancellationToken { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AsyncCollection{T}"/> | ||
/// class for mocking. | ||
/// </summary> | ||
protected AsyncCollection() => | ||
this.CancellationToken = CancellationToken.None; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AsyncCollection{T}"/> | ||
/// class. | ||
/// </summary> | ||
/// <param name="cancellationToken"> | ||
/// The <see cref="CancellationToken"/> used for requests made while | ||
/// enumerating asynchronously. | ||
/// </param> | ||
protected AsyncCollection(CancellationToken cancellationToken) => | ||
this.CancellationToken = cancellationToken; | ||
|
||
/// <summary> | ||
/// Enumerate the values a <see cref="Page{T}"/> at a time. This may | ||
/// make mutliple service requests. | ||
/// </summary> | ||
/// <param name="continuationToken"> | ||
/// A continuation token indicating where to resume paging or null to | ||
/// begin paging from the beginning. | ||
/// </param> | ||
/// <param name="pageSizeHint"> | ||
/// The size of <see cref="Page{T}"/>s that should be requested (from | ||
/// service operations that support it). | ||
/// </param> | ||
/// <returns> | ||
/// An async sequence of <see cref="Page{T}"/>s. | ||
/// </returns> | ||
public abstract IAsyncEnumerable<Page<T>> ByPage( | ||
string continuationToken = default, | ||
int? pageSizeHint = default); | ||
|
||
/// <summary> | ||
/// Enumerate the values in the collection asynchronously. This may | ||
/// make mutliple service requests. | ||
/// </summary> | ||
/// <param name="cancellationToken"> | ||
/// The <see cref="CancellationToken"/> used for requests made while | ||
/// enumerating asynchronously. | ||
/// </param> | ||
/// <returns>An async sequence of values.</returns> | ||
public abstract IAsyncEnumerator<Response<T>> GetAsyncEnumerator(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Creates a string representation of an <see cref="AsyncCollection{T}"/>. | ||
/// </summary> | ||
/// <returns> | ||
/// A string representation of an <see cref="AsyncCollection{T}"/>. | ||
/// </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override string ToString() => base.ToString(); | ||
|
||
/// <summary> | ||
/// Check if two <see cref="AsyncCollection{T}"/> instances are equal. | ||
/// </summary> | ||
/// <param name="obj">The instance to compare to.</param> | ||
/// <returns>True if they're equal, false otherwise.</returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override bool Equals(object obj) => base.Equals(obj); | ||
|
||
/// <summary> | ||
/// Get a hash code for the <see cref="AsyncCollection{T}"/>. | ||
/// </summary> | ||
/// <returns>Hash code for the <see cref="Page{T}"/>.</returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override int GetHashCode() => base.GetHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
|
||
namespace Azure | ||
{ | ||
/// <summary> | ||
/// A single <see cref="Page{T}"/> of values from a request that may return | ||
/// zero or more <see cref="Page{T}"/>s of values. | ||
/// </summary> | ||
/// <typeparam name="T">The type of values.</typeparam> | ||
public readonly struct Page<T> | ||
{ | ||
/// <summary> | ||
/// Gets the values in this <see cref="Page{T}"/>. | ||
/// </summary> | ||
public IReadOnlyList<T> Values { get; } | ||
|
||
/// <summary> | ||
/// Gets the continuation token used to request the next | ||
/// <see cref="Page{T}"/>. The continuation token may be null or | ||
/// empty when there are no more pages. | ||
/// </summary> | ||
public string ContinuationToken { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="Response"/> that provided this <see cref="Page{T}"/>. | ||
/// </summary> | ||
private readonly Response _response; | ||
|
||
/// <summary> | ||
/// Gets the <see cref="Response"/> that provided this | ||
/// <see cref="Page{T}"/>. | ||
/// </summary> | ||
public Response GetRawResponse() => this._response; | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="Page{T}"/>. | ||
/// </summary> | ||
/// <param name="values"> | ||
/// The values in this <see cref="Page{T}"/>. | ||
/// </param> | ||
/// <param name="continuationToken"> | ||
/// The continuation token used to request the next <see cref="Page{T}"/>. | ||
/// </param> | ||
/// <param name="response"> | ||
/// The <see cref="Response"/> that provided this <see cref="Page{T}"/>. | ||
/// </param> | ||
public Page(IReadOnlyList<T> values, string continuationToken, Response response) | ||
{ | ||
this.Values = values; | ||
this.ContinuationToken = continuationToken; | ||
this._response = response; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a string representation of an <see cref="Page{T}"/>. | ||
/// </summary> | ||
/// <returns> | ||
/// A string representation of an <see cref="Page{T}"/>. | ||
/// </returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override string ToString() => base.ToString(); | ||
|
||
/// <summary> | ||
/// Check if two <see cref="Page{T}"/> instances are equal. | ||
/// </summary> | ||
/// <param name="obj">The instance to compare to.</param> | ||
/// <returns>True if they're equal, false otherwise.</returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override bool Equals(object obj) => base.Equals(obj); | ||
|
||
/// <summary> | ||
/// Get a hash code for the <see cref="Page{T}"/>. | ||
/// </summary> | ||
/// <returns>Hash code for the <see cref="Page{T}"/>.</returns> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public override int GetHashCode() => base.GetHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 0 additions & 192 deletions
192
sdk/storage/Azure.Storage.Common/src/AsyncCollection.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.