mycroes / Sally7

C# implementation of Siemens S7 connections with a focus on performance
MIT License
56 stars 22 forks source link

Plumbed in CancellationTokens #27

Closed gfoidl closed 2 years ago

gfoidl commented 2 years ago

For .NET 5 onwards cancellation is supported on all operations. For .NET Standard 2.1 (onwards) most operations support cancellation.

Strictly speaking this change is a binary breaking change, as cancellation tokens are added as additional argument to the methods. Shouldn't be a problem, as version of Sally7 is below 1.0.0 according to SemVer. Besides that I doubt that anyone won't recompile the project here after updating the reference.

Except for S7Connection WriteAsync and ReadAsync new overloads were added, in order to keep the same "usage behavor" of the overloads, as params must be the last argument and usually CancellationTokens are also set last. So this code still works as expected:

IDataItem item0 = null!;
IDataItem item1 = null!;

await s7Connection.ReadAsync(item0, item1);

IDataItem[] dataItems = { item0, item1 };
await s7Connection.ReadAsync(dataItems);

CancellationToken cancellationToken = default;
await s7Connection.ReadAsync(dataItems, cancellationToken);

I used this overloads in a work project already, but added Sally7 therefore as git submodule. So I'd appreciate that this change can be merged, so that the official package could be referenced (and the submodule go away).

mycroes commented 2 years ago

Sorry for my late arrival to the party. Haven't had time to look at this yet, I'll try to do that soonish. I approve of the feature anyway, so I guess I'll merge as-is 😉

mycroes commented 2 years ago

Sorry for the late approval, had a busy time so didn't get to do much here. Actually working on the company PLC infrastructure now as well, so as part of that I have a bit of time for Sally7 as well.

mycroes commented 2 years ago

Just released this as 0.13.0 (currently validating on nuget.org). Thanks again Günther!