Skip to content

Commit 1563475

Browse files
Merge pull request #106 from richardschneider/async-stream
Async streams (C# 8.0)
2 parents e240383 + 7c91838 commit 1563475

File tree

9 files changed

+497
-391
lines changed

9 files changed

+497
-391
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ language: csharp
22
sudo: required
33
mono: none
44
dist: xenial
5-
dotnet: 2.2.300
5+
dotnet: 3.0.100
66
os:
77
- linux
88
- osx
99

1010
script:
1111
- dotnet restore
12-
- dotnet build -c Release --no-restore --framework netstandard2 ./src
13-
- dotnet test -c Release --no-restore --framework netcoreapp2.1 ./test
12+
- dotnet build -c Release --no-restore --framework netcoreapp3.0 ./src
13+
- dotnet test -c Release --no-restore --framework netcoreapp3.0 ./test

appveyor.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ for:
1414
secure: NeX5NCOUXsCLc1UjTJjqB9F02FZ8Wq0VsxqTXC8kBdyK6zjxjebrf/9Da2sY1Kql
1515

1616
configuration: Release
17-
os: Visual Studio 2017
17+
os: Visual Studio 2019
1818

1919
init:
2020
- git config --global core.autocrlf input
@@ -23,17 +23,15 @@ init:
2323
- git config --global user.email "[email protected]"
2424
- git config --global user.name "Appveyor CI"
2525

26-
cache:
27-
- packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
28-
2926
environment:
3027
COVERALLS_REPO_TOKEN:
3128
secure: j4sELCwhVRRjNXFVhjPZjdG4y2itz8jrExhlyDU/lTiLlRQ/P4brB69MGQRFBQae
3229
DOTNET_CLI_TELEMETRY_OPTOUT: 1
3330

3431
# tools we need for bulding/testing/deploying
3532
install:
36-
- choco install gitversion.portable -y
33+
# see https://help.appveyor.com/discussions/problems/24758-gitversion-5-not-working-on-visual-studio-2019-build
34+
- choco install gitversion.portable -y --version 4.0.0
3735
- npm install [email protected] -g
3836
# No longer signing the assembly
3937
#- nuget install secure-file -ExcludeVersion
@@ -46,7 +44,9 @@ nuget:
4644
disable_publish_on_pr: true
4745

4846
before_build:
49-
- ps: gitversion /output buildserver /updateAssemblyInfo >gitversion.log
47+
# - ps: gitversion /output buildserver /updateAssemblyInfo >gitversion.log
48+
- gitversion /output buildserver /updateAssemblyInfo >gitversion
49+
5050
- echo %GitVersion_MajorMinorPatch%
5151
- echo %GitVersion_NuGetVersion%
5252

@@ -55,8 +55,7 @@ build_script:
5555

5656
after_build:
5757
# Build documentation in doc\_site
58-
# v2.43 is requiring VS 2019!!!
59-
- cmd: choco install docfx -y --version 2.42 --force
58+
- cmd: choco install docfx -y
6059
- cmd: builddocs.cmd
6160
- cmd: 7z a -tzip docs.zip doc\_site
6261
- cmd: appveyor PushArtifact docs.zip
@@ -67,7 +66,7 @@ test_script:
6766

6867
after_test:
6968
# Generate coverage report
70-
- dotnet test -c %CONFIGURATION% -f netcoreapp2.1 --no-build --no-restore test /p:CollectCoverage=true
69+
- dotnet test -c %CONFIGURATION% -f netcoreapp3.0 --no-build --no-restore test /p:CollectCoverage=true /p:Include="[Ipfs.Core]*"
7170
- choco install codecov -y
7271
- codecov -f "test/coverage.opencover.xml"
7372
- dotnet tool install --global coveralls.net --version 1.0.0

doc/docfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
],
1717
"properties": {
18-
"TargetFramework": "net45"
18+
"TargetFramework": "netcoreapp3.0"
1919
},
2020

2121
"dest": "api"

src/CoreApi/IGenericApi.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
34
using System.Text;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -114,5 +115,49 @@ Task<IEnumerable<PingResult>> PingAsync(
114115
int count = 10,
115116
CancellationToken cancel = default(CancellationToken)
116117
);
118+
119+
#if ASYNCSTREAM
120+
/// <summary>
121+
/// Send echo requests to a peer.
122+
/// </summary>
123+
/// <param name="peer">
124+
/// The peer ID to receive the echo requests.
125+
/// </param>
126+
/// <param name="count">
127+
/// The number of echo requests to send. Defaults to 10.
128+
/// </param>
129+
/// <param name="cancel">
130+
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
131+
/// </param>
132+
/// <returns>
133+
/// An asynchronous stream of <see cref="PingResult"/>.
134+
/// </returns>
135+
IAsyncEnumerable<PingResult> Ping(
136+
MultiHash peer,
137+
int count = 10,
138+
CancellationToken cancel = default
139+
);
140+
141+
/// <summary>
142+
/// Send echo requests to a peer.
143+
/// </summary>
144+
/// <param name="address">
145+
/// The address of a peer to receive the echo requests.
146+
/// </param>
147+
/// <param name="count">
148+
/// The number of echo requests to send. Defaults to 10.
149+
/// </param>
150+
/// <param name="cancel">
151+
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
152+
/// </param>
153+
/// <returns>
154+
/// An asynchronous stream of <see cref="PingResult"/>.
155+
/// </returns>
156+
IAsyncEnumerable<PingResult> Ping(
157+
MultiAddress address,
158+
int count = 10,
159+
CancellationToken cancel = default
160+
);
161+
#endif
117162
}
118163
}

src/IpfsCore.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard14;netstandard2;net45</TargetFrameworks>
4+
<TargetFrameworks>netstandard14;netstandard2;net45;netcoreapp3.0</TargetFrameworks>
55
<AssemblyName>Ipfs.Core</AssemblyName>
66
<RootNamespace>Ipfs</RootNamespace>
77
<DebugType>portable</DebugType>
@@ -63,4 +63,9 @@
6363
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard14'">
6464
<DefineConstants>NETSTANDARD14</DefineConstants>
6565
</PropertyGroup>
66+
67+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0'">
68+
<DefineConstants>ASYNCSTREAM</DefineConstants>
69+
</PropertyGroup>
70+
6671
</Project>

test/CoreApi/ObjectStatTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace Ipfs.CoreApi
7+
{
8+
[TestClass]
9+
public class ObjectStatTest
10+
{
11+
[TestMethod]
12+
public void Properties()
13+
{
14+
var stat = new ObjectStat
15+
{
16+
BlockSize = 1,
17+
CumulativeSize = 2,
18+
DataSize = 3,
19+
LinkCount = 4,
20+
LinkSize = 5
21+
};
22+
Assert.AreEqual(1, stat.BlockSize);
23+
Assert.AreEqual(2, stat.CumulativeSize);
24+
Assert.AreEqual(3, stat.DataSize);
25+
Assert.AreEqual(4, stat.LinkCount);
26+
Assert.AreEqual(5, stat.LinkSize);
27+
}
28+
29+
}
30+
}

test/CoreApi/PingResultTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace Ipfs.CoreApi
7+
{
8+
[TestClass]
9+
public class PingResultTest
10+
{
11+
[TestMethod]
12+
public void Properties()
13+
{
14+
var time = TimeSpan.FromSeconds(3);
15+
var r = new PingResult
16+
{
17+
Success = true,
18+
Text = "ping",
19+
Time = time
20+
};
21+
Assert.AreEqual(true, r.Success);
22+
Assert.AreEqual("ping", r.Text);
23+
Assert.AreEqual(time, r.Time);
24+
}
25+
26+
}
27+
}

test/IpfsCoreTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net45;netcoreapp1.1;netcoreapp2.1</TargetFrameworks>
4+
<TargetFrameworks>net45;netcoreapp1.1;netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
<DebugType>portable</DebugType>

0 commit comments

Comments
 (0)