-
Notifications
You must be signed in to change notification settings - Fork 13
Async streaming extension methods + ConfigureAwaitFalse improvements #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FluttercordKN
wants to merge
1
commit into
Knoema:master
Choose a base branch
from
FluttercordKN:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,37 @@ | ||
| using Knoema.Data; | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Knoema | ||
| { | ||
| #if NETCOREAPP3_1_OR_GREATER | ||
| public static class ClientExtension | ||
| { | ||
| public static async IAsyncEnumerable<RegularTimeSeriesRawData> GetDataAsync(this Client client, PivotRequest pivot) | ||
| { | ||
| var response = await client.GetDataBegin(pivot); | ||
| foreach (var item in response.Data) | ||
| yield return item; | ||
| while (!string.IsNullOrEmpty(response.ContinuationToken)) | ||
| { | ||
| response = await client.GetDataStreaming(response.ContinuationToken); | ||
| foreach (var item in response.Data) | ||
| yield return item; | ||
| } | ||
| } | ||
|
|
||
| public static async IAsyncEnumerable<FlatTimeSeriesRawData> GetFlatDataAsync(this Client client, PivotRequest pivot) | ||
| { | ||
| var response = await client.GetFlatDataBegin(pivot); | ||
| foreach (var item in response.Data) | ||
| yield return item; | ||
| while (!string.IsNullOrEmpty(response.ContinuationToken)) | ||
| { | ||
| response = await client.GetFlatDataStreaming(response.ContinuationToken); | ||
| foreach (var item in response.Data) | ||
| yield return item; | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
Knoema.UnitTestsNetCore31/Knoema.UnitTestsNetCore31.csproj
This file contains hidden or 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,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
|
|
||
| <AssemblyName>Knoema.UnitTestsNetCore31</AssemblyName> | ||
|
|
||
| <RootNamespace>Knoema.UnitTestsNetCore31</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
| <PackageReference Include="MSTest.TestAdapter" Version="2.2.3" /> | ||
| <PackageReference Include="MSTest.TestFramework" Version="2.2.3" /> | ||
| <PackageReference Include="coverlet.collector" Version="3.0.3"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="System.Linq.Async" Version="5.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Knoema.Client\Knoema.Client.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,52 @@ | ||
| using Knoema.Data; | ||
|
|
||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Knoema.UnitTestsNetCore31 | ||
| { | ||
| [TestClass] | ||
| public class KnoemaClientTests | ||
| { | ||
| [TestMethod] | ||
| public async Task GetDataStreamingAsync() | ||
| { | ||
| var instance = new Client("knoema.com"); | ||
| var request = new PivotRequest | ||
| { | ||
| Dataset = "WBWDI2019Jan", | ||
| Header = new List<PivotRequestItem> | ||
| { | ||
| new PivotRequestItem | ||
| { | ||
| DimensionId = "Time", | ||
| UiMode = "AllData" | ||
| } | ||
| }, | ||
| Stub = new List<PivotRequestItem> | ||
| { | ||
| new PivotRequestItem | ||
| { | ||
| DimensionId = "country", | ||
| Members = Enumerable.Range(0, 100).Select(i => 1000000 + i * 10).Cast<object>().ToArray() | ||
| }, | ||
| new PivotRequestItem | ||
| { | ||
| DimensionId = "series", | ||
| Members = Enumerable.Range(0, 100).Select(i => 1000000 + i * 10).Cast<object>().ToArray() | ||
| } | ||
| }, | ||
| Frequencies = new List<string> { "A" }, | ||
| DetailColumns = new[] { "*" } | ||
| }; | ||
|
|
||
| var result = await instance.GetDataAsync(request).ToListAsync(); | ||
|
|
||
| Console.WriteLine(result.Count); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no assert. Maybe it's worth adding specific elements and check the expected ts count. No exceptions are good, but it might be not enough. |
||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably stops the project opening on old VS versions