Remove Task/Func paging methods, c# types are too strict for that

This commit is contained in:
Jonas Dellinger 2020-06-13 13:28:50 +02:00
parent de98bc012f
commit df009e0316
3 changed files with 1 additions and 276 deletions

View File

@ -59,7 +59,7 @@ namespace Example.CLI.PersistentConfig
var me = await spotify.UserProfile.Current();
Console.WriteLine($"Welcome {me.DisplayName} ({me.Id}), your authenticated!");
var playlists = await spotify.PaginateAll(spotify.Playlists.CurrentUsers());
var playlists = await spotify.PaginateAll(await spotify.Playlists.CurrentUsers().ConfigureAwait(false));
Console.WriteLine($"Total Playlists in your Account: {playlists.Count}");
_server.Dispose();

View File

@ -109,28 +109,6 @@ namespace SpotifyAPI.Web
/// <returns>A list containing all fetched pages</returns>
Task<IList<T>> PaginateAll<T>(IPaginatable<T> firstPage, IPaginator? paginator = default!);
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="getFirstPage">A function to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>A list containing all fetched pages</returns>
Task<IList<T>> PaginateAll<T>(Func<Task<IPaginatable<T>>> getFirstPage, IPaginator? paginator = default!);
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="firstPageTask">A task to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>A list containing all fetched pages</returns>
Task<IList<T>> PaginateAll<T>(Task<IPaginatable<T>> firstPageTask, IPaginator? paginator = default!);
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
@ -150,44 +128,6 @@ namespace SpotifyAPI.Web
IPaginator? paginator = default!
);
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
/// To workaround this limitation, the mapper is required and needs to point to the correct next pagination.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="getFirstPage">A function to retrive the first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns></returns>
Task<IList<T>> PaginateAll<T, TNext>(
Func<Task<IPaginatable<T, TNext>>> getFirstPage,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = default!
);
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
/// To workaround this limitation, the mapper is required and needs to point to the correct next pagination.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="firstPageTask">A Task to retrive the first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns></returns>
Task<IList<T>> PaginateAll<T, TNext>(
Task<IPaginatable<T, TNext>> firstPageTask,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = default!
);
#if NETSTANDARD2_1
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
@ -205,38 +145,6 @@ namespace SpotifyAPI.Web
CancellationToken cancellationToken = default!
);
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="getFirstPage">A Function to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">An optional Cancellation Token</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>An iterable IAsyncEnumerable</returns>
IAsyncEnumerable<T> Paginate<T>(
Func<Task<IPaginatable<T>>> getFirstPage,
IPaginator? paginator = default!,
CancellationToken cancellationToken = default!
);
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="firstPageTask">A Task to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">An optional Cancellation Token</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>An iterable IAsyncEnumerable</returns>
IAsyncEnumerable<T> Paginate<T>(
Task<IPaginatable<T>> firstPageTask,
IPaginator? paginator = default!,
CancellationToken cancellationToken = default!
);
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
@ -258,47 +166,6 @@ namespace SpotifyAPI.Web
CancellationToken cancellationToken = default!
);
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
/// To workaround this limitation, the mapper is required and needs to point to the correct next pagination.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="getFirstPage">A Function to retrive the first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">An optional Cancellation Token</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns></returns>
IAsyncEnumerable<T> Paginate<T, TNext>(
Func<Task<IPaginatable<T, TNext>>> getFirstPage,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = default!,
CancellationToken cancellationToken = default!
);
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
/// To workaround this limitation, the mapper is required and needs to point to the correct next pagination.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="firstPageTask">A Task to retrive the first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">An optional Cancellation Token</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns></returns>
IAsyncEnumerable<T> Paginate<T, TNext>(
Task<IPaginatable<T, TNext>> firstPageTask,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = default!,
CancellationToken cancellationToken = default!
);
#endif
}
}

View File

@ -96,41 +96,6 @@ namespace SpotifyAPI.Web
return (paginator ?? DefaultPaginator).PaginateAll(firstPage, _apiConnector);
}
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="getFirstPage">A function to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>A list containing all fetched pages</returns>
public async Task<IList<T>> PaginateAll<T>(Func<Task<IPaginatable<T>>> getFirstPage, IPaginator? paginator = null)
{
Ensure.ArgumentNotNull(getFirstPage, nameof(getFirstPage));
var firstPage = await getFirstPage().ConfigureAwait(false);
return await (paginator ?? DefaultPaginator).PaginateAll(firstPage, _apiConnector).ConfigureAwait(false);
}
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="firstPageTask">A task to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>A list containing all fetched pages</returns>
public async Task<IList<T>> PaginateAll<T>(Task<IPaginatable<T>> firstPageTask, IPaginator? paginator = null)
{
Ensure.ArgumentNotNull(firstPageTask, nameof(firstPageTask));
var firstPage = await firstPageTask.ConfigureAwait(false);
return await (paginator ?? DefaultPaginator).PaginateAll(firstPage, _apiConnector).ConfigureAwait(false);
}
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
@ -153,57 +118,6 @@ namespace SpotifyAPI.Web
return (paginator ?? DefaultPaginator).PaginateAll(firstPage, mapper, _apiConnector);
}
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
/// To workaround this limitation, the mapper is required and needs to point to the correct next pagination.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="getFirstPage">A function to retrive the first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns></returns>
public async Task<IList<T>> PaginateAll<T, TNext>(
Func<Task<IPaginatable<T, TNext>>> getFirstPage,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = null
)
{
Ensure.ArgumentNotNull(getFirstPage, nameof(getFirstPage));
var firstPage = await getFirstPage().ConfigureAwait(false);
return await (paginator ?? DefaultPaginator).PaginateAll(firstPage, mapper, _apiConnector).ConfigureAwait(false);
}
/// <summary>
/// Fetches all pages and returns them grouped in a list.
/// Some responses (e.g search response) have the pagination nested in a JSON Property.
/// To workaround this limitation, the mapper is required and needs to point to the correct next pagination.
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="firstPageTask">A Task to retrive the first page, will be included in the output list!</param>
/// <param name="mapper">A function which maps response objects to the next paging object</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <typeparam name="TNext">The Response-Type</typeparam>
/// <returns></returns>
public async Task<IList<T>> PaginateAll<T, TNext>(
Task<IPaginatable<T, TNext>> firstPageTask,
Func<TNext, IPaginatable<T, TNext>> mapper,
IPaginator? paginator = null
)
{
Ensure.ArgumentNotNull(firstPageTask, nameof(firstPageTask));
var firstPage = await firstPageTask.ConfigureAwait(false);
return await (paginator ?? DefaultPaginator).PaginateAll(firstPage, mapper, _apiConnector).ConfigureAwait(false);
}
#if NETSTANDARD2_1
/// <summary>
@ -225,62 +139,6 @@ namespace SpotifyAPI.Web
return (paginator ?? DefaultPaginator).Paginate(firstPage, _apiConnector, cancellationToken);
}
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="getFirstPage">A Function to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">An optional Cancellation Token</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>An iterable IAsyncEnumerable</returns>
public async IAsyncEnumerable<T> Paginate<T>(
Func<Task<IPaginatable<T>>> getFirstPage,
IPaginator? paginator = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default
)
{
Ensure.ArgumentNotNull(getFirstPage, nameof(getFirstPage));
var firstPage = await getFirstPage().ConfigureAwait(false);
await foreach (var item in (paginator ?? DefaultPaginator)
.Paginate(firstPage, _apiConnector)
.WithCancellation(cancellationToken)
)
{
yield return item;
}
}
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// The default paginator will fetch all available resources without a delay between requests.
/// This can drain your request limit quite fast, so consider using a custom paginator with delays.
/// </summary>
/// <param name="firstPageTask">A Task to retrive the first page, will be included in the output list!</param>
/// <param name="paginator">Optional. If not supplied, DefaultPaginator will be used</param>
/// <param name="cancellationToken">An optional Cancellation Token</param>
/// <typeparam name="T">The Paging-Type</typeparam>
/// <returns>An iterable IAsyncEnumerable</returns>
public async IAsyncEnumerable<T> Paginate<T>(
Task<IPaginatable<T>> firstPageTask,
IPaginator? paginator = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Ensure.ArgumentNotNull(firstPageTask, nameof(firstPageTask));
var firstPage = await firstPageTask.ConfigureAwait(false);
await foreach (var item in (paginator ?? DefaultPaginator)
.Paginate(firstPage, _apiConnector)
.WithCancellation(cancellationToken)
)
{
yield return item;
}
}
/// <summary>
/// Paginate through pages by using IAsyncEnumerable, introduced in C# 8
/// Some responses (e.g search response) have the pagination nested in a JSON Property.