Skip to content

Commit a92382d

Browse files
author
Oren (electricessence)
committed
Updated packaging.
Added nullable ref checking.
1 parent 728ee31 commit a92382d

File tree

10 files changed

+93
-99
lines changed

10 files changed

+93
-99
lines changed

Extensions.Observable.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,26 @@ public static partial class DataFlowExtensions
77
class Observer<T> : IObserver<T>, IDisposable
88
{
99
public static IObserver<T> New(
10-
Action<T> onNext,
11-
Action<Exception> onError,
12-
Action onCompleted)
10+
Action<T>? onNext,
11+
Action<Exception>? onError,
12+
Action? onCompleted)
1313
=> new Observer<T>()
1414
{
1515
_onNext = onNext,
1616
_onError = onError,
1717
_onCompleted = onCompleted
1818
};
1919

20-
Action _onCompleted;
21-
Action<Exception> _onError;
22-
Action<T> _onNext;
20+
Action? _onCompleted;
21+
Action<Exception>? _onError;
22+
Action<T>? _onNext;
2323

2424

25-
public void OnNext(T value)
26-
{
27-
_onNext?.Invoke(value);
28-
}
25+
public void OnNext(T value) => _onNext?.Invoke(value);
2926

30-
public void OnError(Exception error)
31-
{
32-
_onError?.Invoke(error);
33-
}
27+
public void OnError(Exception error) => _onError?.Invoke(error);
3428

35-
public void OnCompleted()
36-
{
37-
_onCompleted?.Invoke();
38-
}
29+
public void OnCompleted() => _onCompleted?.Invoke();
3930

4031

4132
public void Dispose()
@@ -49,12 +40,12 @@ public void Dispose()
4940
public static IDisposable Subscribe<T>(this IObservable<T> observable,
5041
Action<T> onNext,
5142
Action<Exception> onError,
52-
Action onCompleted = null)
43+
Action? onCompleted = null)
5344
=> observable.Subscribe(Observer<T>.New(onNext, onError, onCompleted));
5445

5546
public static IDisposable Subscribe<T>(this IObservable<T> observable,
5647
Action<T> onNext,
57-
Action onCompleted = null)
48+
Action? onCompleted = null)
5849
=> observable.Subscribe(Observer<T>.New(onNext, null, onCompleted));
5950

6051
}

Extensions.Pipe.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public static TBlock Pipe<T, TBlock>(this ISourceBlock<T> source,
2020
TBlock target)
2121
where TBlock : ITargetBlock<T>
2222
{
23-
if (source == null)
23+
if (source is null)
2424
throw new NullReferenceException();
25-
if (target == null)
25+
if (target is null)
2626
throw new ArgumentNullException(nameof(target));
2727
Contract.EndContractBlock();
2828

@@ -40,11 +40,11 @@ public static TBlock Pipe<T, TBlock>(this ISourceBlock<T> source,
4040
/// <param name="options">Optional execution options.</param>
4141
/// <returns>The source block created.</returns>
4242
public static IReceivableSourceBlock<TOut> Pipe<TIn, TOut>(this ISourceBlock<TIn> source,
43-
Func<TIn, TOut> transform, ExecutionDataflowBlockOptions options = null)
43+
Func<TIn, TOut> transform, ExecutionDataflowBlockOptions? options = null)
4444
{
45-
if (source == null)
45+
if (source is null)
4646
throw new NullReferenceException();
47-
if (transform == null)
47+
if (transform is null)
4848
throw new ArgumentNullException(nameof(transform));
4949
Contract.EndContractBlock();
5050

@@ -62,11 +62,11 @@ public static IReceivableSourceBlock<TOut> Pipe<TIn, TOut>(this ISourceBlock<TIn
6262
/// <param name="options">Optional execution options.</param>
6363
/// <returns>The source block created.</returns>
6464
public static IReceivableSourceBlock<TOut> PipeAsync<TIn, TOut>(this ISourceBlock<TIn> source,
65-
Func<TIn, Task<TOut>> transform, ExecutionDataflowBlockOptions options = null)
65+
Func<TIn, Task<TOut>> transform, ExecutionDataflowBlockOptions? options = null)
6666
{
67-
if (source == null)
67+
if (source is null)
6868
throw new NullReferenceException();
69-
if (transform == null)
69+
if (transform is null)
7070
throw new ArgumentNullException(nameof(transform));
7171
Contract.EndContractBlock();
7272

@@ -85,15 +85,15 @@ public static IReceivableSourceBlock<TOut> PipeAsync<TIn, TOut>(this ISourceBloc
8585
/// <returns>The ActionBlock created.</returns>
8686
public static ActionBlock<T> Pipe<T>(this ISourceBlock<T> source,
8787
Action<T> handler,
88-
ExecutionDataflowBlockOptions options = null)
88+
ExecutionDataflowBlockOptions? options = null)
8989
{
90-
if (source == null)
90+
if (source is null)
9191
throw new NullReferenceException();
92-
if (handler == null)
92+
if (handler is null)
9393
throw new ArgumentNullException(nameof(handler));
9494
Contract.EndContractBlock();
9595

96-
var receiver = options == null
96+
var receiver = options is null
9797
? new ActionBlock<T>(handler)
9898
: new ActionBlock<T>(handler, options);
9999

@@ -111,15 +111,15 @@ public static ActionBlock<T> Pipe<T>(this ISourceBlock<T> source,
111111
/// <returns>The ActionBlock created.</returns>
112112
public static ActionBlock<T> PipeAsync<T>(this ISourceBlock<T> source,
113113
Func<T, Task> handler,
114-
ExecutionDataflowBlockOptions options = null)
114+
ExecutionDataflowBlockOptions? options = null)
115115
{
116-
if (source == null)
116+
if (source is null)
117117
throw new NullReferenceException();
118-
if (handler == null)
118+
if (handler is null)
119119
throw new ArgumentNullException(nameof(handler));
120120
Contract.EndContractBlock();
121121

122-
var receiver = options == null
122+
var receiver = options is null
123123
? new ActionBlock<T>(handler)
124124
: new ActionBlock<T>(handler, options);
125125

Extensions.TransformBlock.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace Open.Threading.Dataflow
66
{
77
public static class TransformBlock
88
{
9-
public static TransformBlock<TIn, TOut> New<TIn, TOut>(Func<TIn, TOut> pipe, ExecutionDataflowBlockOptions options = null)
10-
=> options == null
9+
public static TransformBlock<TIn, TOut> New<TIn, TOut>(Func<TIn, TOut> pipe, ExecutionDataflowBlockOptions? options = null)
10+
=> options is null
1111
? new TransformBlock<TIn, TOut>(pipe)
1212
: new TransformBlock<TIn, TOut>(pipe, options);
1313

14-
public static TransformBlock<TIn, TOut> NewAsync<TIn, TOut>(Func<TIn, Task<TOut>> pipe, ExecutionDataflowBlockOptions options = null)
15-
=> options == null
14+
public static TransformBlock<TIn, TOut> NewAsync<TIn, TOut>(Func<TIn, Task<TOut>> pipe, ExecutionDataflowBlockOptions? options = null)
15+
=> options is null
1616
? new TransformBlock<TIn, TOut>(pipe)
1717
: new TransformBlock<TIn, TOut>(pipe, options);
1818
}

Extensions._.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ public static Task CompleteAsync(this IDataflowBlock source)
1717
return source.Completion;
1818
}
1919

20-
public static ISourceBlock<T> Buffer<T>(this ISourceBlock<T> source, DataflowBlockOptions dataflowBlockOptions = null)
20+
public static ISourceBlock<T> Buffer<T>(this ISourceBlock<T> source, DataflowBlockOptions? dataflowBlockOptions = null)
2121
{
22-
if (source == null)
22+
if (source is null)
2323
throw new NullReferenceException();
2424
Contract.EndContractBlock();
2525

26-
var output = dataflowBlockOptions == null
26+
var output = dataflowBlockOptions is null
2727
? new BufferBlock<T>()
2828
: new BufferBlock<T>(dataflowBlockOptions);
2929
source.LinkToWithCompletion(output);
3030
return output;
3131
}
3232

33-
public static ISourceBlock<T> BufferMany<T>(this ISourceBlock<T[]> source, ExecutionDataflowBlockOptions dataflowBlockOptions = null)
33+
public static ISourceBlock<T> BufferMany<T>(this ISourceBlock<T[]> source, ExecutionDataflowBlockOptions? dataflowBlockOptions = null)
3434
{
35-
if (source == null)
35+
if (source is null)
3636
throw new NullReferenceException();
3737
Contract.EndContractBlock();
3838

39-
var output = dataflowBlockOptions == null
39+
var output = dataflowBlockOptions is null
4040
? new TransformManyBlock<T[], T>(t => t)
4141
: new TransformManyBlock<T[], T>(t => t, dataflowBlockOptions); ;
4242
source.LinkToWithCompletion(output);
@@ -45,13 +45,13 @@ public static ISourceBlock<T> BufferMany<T>(this ISourceBlock<T[]> source, Execu
4545

4646
public static ISourceBlock<T[]> Batch<T>(this ISourceBlock<T> source,
4747
int batchSize,
48-
GroupingDataflowBlockOptions dataflowBlockOptions = null)
48+
GroupingDataflowBlockOptions? dataflowBlockOptions = null)
4949
{
50-
if (source == null)
50+
if (source is null)
5151
throw new NullReferenceException();
5252
Contract.EndContractBlock();
5353

54-
var batchBlock = dataflowBlockOptions == null
54+
var batchBlock = dataflowBlockOptions is null
5555
? new BatchBlock<T>(batchSize)
5656
: new BatchBlock<T>(batchSize, dataflowBlockOptions);
5757

@@ -62,9 +62,9 @@ public static ISourceBlock<T[]> Batch<T>(this ISourceBlock<T> source,
6262
public static int ToTargetBlock<T>(this IEnumerable<T> source,
6363
ITargetBlock<T> target)
6464
{
65-
if (source == null)
65+
if (source is null)
6666
throw new NullReferenceException();
67-
if (target == null)
67+
if (target is null)
6868
throw new ArgumentNullException(nameof(target));
6969
Contract.EndContractBlock();
7070

@@ -83,9 +83,9 @@ public static Task<int> ToTargetBlockAsync<T>(this IEnumerable<T> source,
8383
ITargetBlock<T> target,
8484
CancellationToken cancellationToken = default)
8585
{
86-
if (source == null)
86+
if (source is null)
8787
throw new NullReferenceException();
88-
if (target == null)
88+
if (target is null)
8989
throw new ArgumentNullException(nameof(target));
9090
Contract.EndContractBlock();
9191

@@ -115,7 +115,7 @@ async Task<int> ToTargetBlockAsyncCore()
115115
public static async Task<List<T>> ToListAsync<T>(this IReceivableSourceBlock<T> source,
116116
CancellationToken cancellationToken = default)
117117
{
118-
if (source == null)
118+
if (source is null)
119119
throw new NullReferenceException();
120120
Contract.EndContractBlock();
121121

@@ -140,7 +140,7 @@ public static ISourceBlock<T> AsBufferBlock<T>(this IEnumerable<T> source,
140140
int capacity = DataflowBlockOptions.Unbounded,
141141
CancellationToken cancellationToken = default)
142142
{
143-
if (source == null)
143+
if (source is null)
144144
throw new NullReferenceException();
145145
Contract.EndContractBlock();
146146

@@ -175,7 +175,7 @@ public static async Task<int> AllLinesTo(this TextReader source,
175175
bool completeAndAwait = false,
176176
CancellationToken cancellationToken = default)
177177
{
178-
if (source == null)
178+
if (source is null)
179179
throw new NullReferenceException();
180180
Contract.EndContractBlock();
181181

@@ -204,7 +204,7 @@ public static async Task<int> AllLinesTo<T>(this TextReader source,
204204
bool completeAndAwait = false,
205205
CancellationToken cancellationToken = default)
206206
{
207-
if (source == null)
207+
if (source is null)
208208
throw new NullReferenceException();
209209
Contract.EndContractBlock();
210210

Filters/Changed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public ChangedFilter(ITargetBlock<T> target, DataflowMessageStatus defaultRespon
1010
}
1111

1212
readonly object SyncLock = new object();
13-
T _last;
13+
T _last = default!;
1414

1515
protected override bool Accept(T messageValue)
1616
=> ThreadSafety.LockConditional(
1717
SyncLock,
18-
() => !messageValue.Equals(_last),
18+
() => !(messageValue is null ? _last is null : messageValue.Equals(_last)),
1919
() => _last = messageValue);
2020
}
2121

Filters/Filter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace Open.Threading.Dataflow
66
internal class TargetBlockFilter<T> : TargetBlockFilterBase<T>
77
{
88
private readonly DataflowMessageStatus _filterDeclineStatus;
9-
private readonly Func<T, bool> _filter;
9+
private readonly Func<T, bool>? _filter;
1010

1111
public TargetBlockFilter(
1212
ITargetBlock<T> target,
1313
DataflowMessageStatus filterDeclineStatus,
14-
Func<T, bool> filter) : base(target)
14+
Func<T, bool>? filter) : base(target)
1515
{
1616
_filter = filter;
1717
switch (filterDeclineStatus)
@@ -29,7 +29,7 @@ public TargetBlockFilter(
2929
private static readonly ITargetBlock<T> NullTarget = DataflowBlock.NullTarget<T>();
3030

3131
protected virtual bool Accept(T messageValue)
32-
=> _filter(messageValue);
32+
=> _filter!(messageValue);
3333

3434
public override DataflowMessageStatus OfferMessage(
3535
DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T> source, bool consumeToAccept)
File renamed without changes.

Open.Threading.Dataflow.csproj

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5-
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
6-
<PackageLicenseUrl></PackageLicenseUrl>
7-
<Description>Useful set of extensions and classes for simplifying Dataflow implementations.
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8+
<Authors>electricessence</Authors>
9+
<Description>
10+
Useful set of extensions and classes for simplifying Dataflow implementations.
811

9-
Part of the "Open" set of libraries.</Description>
10-
<Authors>electricesssence</Authors>
11-
<Company />
12-
<Product />
13-
<Copyright>https://github.com/electricessence/Open.Threading.Dataflow/blob/master/LISCENSE.md</Copyright>
14-
<PackageProjectUrl>https://github.com/electricessence/Open.Threading.Dataflow/</PackageProjectUrl>
15-
<RepositoryUrl>https://github.com/electricessence/Open.Threading.Dataflow/</RepositoryUrl>
16-
<RepositoryType>git</RepositoryType>
17-
<PackageTags>dotnet, dotnet-core, dotnetcore, cs, dataflow, tpl, extensions</PackageTags>
18-
<Version>2.3.5</Version>
19-
<PackageReleaseNotes></PackageReleaseNotes>
20-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
21-
</PropertyGroup>
12+
Part of the "Open" set of libraries.
13+
</Description>
14+
<PackageTags>dataflow;tpl;extensions</PackageTags>
15+
<Copyright>© electricessence (Oren F.) All rights reserved.</Copyright>
16+
<PackageProjectUrl>https://github.com/electricessence/Open.Threading.Dataflow/</PackageProjectUrl>
17+
<RepositoryUrl>https://github.com/electricessence/Open.Threading.Dataflow/</RepositoryUrl>
18+
<RepositoryType>git</RepositoryType>
19+
<Version>2.4.0</Version>
20+
<PackageReleaseNotes></PackageReleaseNotes>
21+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
22+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
23+
<IncludeSymbols>true</IncludeSymbols>
24+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
25+
<PackageIcon>logo.png</PackageIcon>
26+
</PropertyGroup>
2227

23-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
24-
<LangVersion>latest</LangVersion>
25-
</PropertyGroup>
28+
<ItemGroup>
29+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
30+
</ItemGroup>
2631

27-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
28-
<LangVersion>latest</LangVersion>
29-
</PropertyGroup>
32+
<ItemGroup>
33+
<None Remove=".git" />
34+
<None Remove=".gitignore" />
35+
<None Include="logo.png">
36+
<Pack>True</Pack>
37+
<PackagePath></PackagePath>
38+
</None>
39+
</ItemGroup>
3040

31-
<ItemGroup>
32-
<None Remove=".git" />
33-
<None Remove=".gitignore" />
34-
<None Remove="LISCENSE.md" />
35-
<None Remove="README.md" />
36-
</ItemGroup>
37-
38-
<ItemGroup>
39-
<PackageReference Include="Open.Threading" Version="1.5.4" />
40-
<PackageReference Include="Open.Threading.Tasks" Version="1.1.3" />
41-
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
42-
</ItemGroup>
41+
<ItemGroup>
42+
<PackageReference Include="Open.Threading" Version="1.6.0" />
43+
<PackageReference Include="Open.Threading.Tasks" Version="1.2.1" />
44+
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.11.1" />
45+
</ItemGroup>
4346

4447
</Project>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
Useful set of extensions and classes for simplifying Dataflow implementations.
44

5-
[![NuGet](http://img.shields.io/nuget/v/Open.Threading.Dataflow.svg)](https://www.nuget.org/packages/Open.Threading.Dataflow/)
5+
[![NuGet](https://img.shields.io/nuget/v/Open.Threading.Dataflow.svg)](https://www.nuget.org/packages/Open.Threading.Dataflow/)

logo.png

54.6 KB
Loading

0 commit comments

Comments
 (0)