Zomp.SyncMethodGenerator
1.0.2
See the version list below for details.
dotnet add package Zomp.SyncMethodGenerator --version 1.0.2
NuGet\Install-Package Zomp.SyncMethodGenerator -Version 1.0.2
<PackageReference Include="Zomp.SyncMethodGenerator" Version="1.0.2" />
paket add Zomp.SyncMethodGenerator --version 1.0.2
#r "nuget: Zomp.SyncMethodGenerator, 1.0.2"
// Install Zomp.SyncMethodGenerator as a Cake Addin #addin nuget:?package=Zomp.SyncMethodGenerator&version=1.0.2 // Install Zomp.SyncMethodGenerator as a Cake Tool #tool nuget:?package=Zomp.SyncMethodGenerator&version=1.0.2
Sync Method Generator
This .NET source generator produces a sync method from an async one.
Use cases
- A library which exposes both sync and async version of a method
- An application has to process two kinds of data in the same way:
- Large data from I/O which cannot be stored in memory before processing: Original async method
- Small sample of data in memory, usually a sample of the larger data: Generated sync method
How it works
Add CreateSyncVersionAttribute
to your async method in your partial
class
[Zomp.SyncMethodGenerator.CreateSyncVersion]
static async Task WriteAsync(ReadOnlyMemory<byte> buffer, Stream stream,
CancellationToken ct)
=> await stream.WriteAsync(buffer, ct).ConfigureAwait(true);
And it will generate a sync version of the method:
static void Write(ReadOnlySpan<byte> buffer, Stream stream)
=> stream.Write(buffer);
A list of changes applied to the new synchronized method:
Remove async modifier
Remove await from methods as well as
foreach
statementChange types
From To Task or ValueTask void Task<T> or ValueTask<T> T IAsyncEnumerable<T> IEnumerable<T> IAsyncEnumerator<T> IEnumerator<T> Memory<T> Span<T> ReadOnlyMemory<T> ReadOnlySpan<T> Remove parameters
Invocation changes
- Remove ConfigureAwait
- Remove WithCancellation
- Remove
Async
suffix from method calls (e.g. MoveNextAsync becomes MoveNext) - Remove CancellationToken parameter
- Remove IProgress<T>.Report(T) call
- Remove Memory<T>.Span property
Remove
CreateSyncVersionAttribute
Update XML documentation
Installation
To add the library use:
dotnet add package Zomp.SyncMethodGenerator
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Zomp.SyncMethodGenerator:
Repository | Stars |
---|---|
Zeugma440/atldotnet
Fully managed, portable and easy-to-use C# library to read and edit audio data and metadata (tags) from various audio formats, playlists and CUE sheets
|
|
SineVector241/VoiceCraft-MCBE_Proximity_Chat
VoiceCraft software to implement proximity VC for Minecraft Bedrock Edition
|
Version | Downloads | Last updated |
---|---|---|
1.4.14 | 397 | 8/7/2024 |
1.4.13 | 399 | 7/21/2024 |
1.4.11 | 664 | 7/15/2024 |
1.4.10 | 589 | 7/13/2024 |
1.4.8 | 207 | 7/8/2024 |
1.4.3 | 225 | 6/27/2024 |
1.4.1 | 251 | 5/21/2024 |
1.3.44 | 195 | 5/14/2024 |
1.3.43 | 274 | 4/26/2024 |
1.3.40 | 481 | 4/11/2024 |
1.3.39 | 229 | 4/9/2024 |
1.3.38 | 364 | 3/23/2024 |
1.3.36 | 197 | 3/20/2024 |
1.3.35 | 77 | 3/19/2024 |
1.3.33 | 152 | 3/18/2024 |
1.3.28 | 153 | 3/18/2024 |
1.3.27 | 179 | 3/17/2024 |
1.3.24 | 362 | 3/12/2024 |
1.3.23 | 222 | 3/12/2024 |
1.3.21 | 180 | 3/11/2024 |
1.3.20 | 211 | 3/11/2024 |
1.3.18 | 181 | 3/10/2024 |
1.3.17 | 259 | 2/26/2024 |
1.3.16 | 295 | 2/26/2024 |
1.3.13 | 205 | 2/25/2024 |
1.3.8-beta | 185 | 2/12/2024 |
1.3.6 | 275 | 1/26/2024 |
1.3.5 | 193 | 1/21/2024 |
1.3.1 | 292 | 1/17/2024 |
1.2.24 | 205 | 1/14/2024 |
1.2.18 | 172 | 1/5/2024 |
1.2.16 | 203 | 1/5/2024 |
1.2.13 | 176 | 1/4/2024 |
1.2.12 | 173 | 1/4/2024 |
1.2.8 | 172 | 1/3/2024 |
1.2.3 | 418 | 11/20/2023 |
1.2.1 | 187 | 11/13/2023 |
1.1.2 | 798 | 8/8/2023 |
1.0.14 | 261 | 8/4/2023 |
1.0.12 | 30,162 | 8/3/2023 |
1.0.11 | 233 | 8/2/2023 |
1.0.5 | 155 | 7/31/2023 |
1.0.3 | 146 | 7/29/2023 |
1.0.2 | 160 | 7/29/2023 |
1.0.1 | 221 | 7/27/2023 |
0.1.39-alpha | 506 | 1/25/2023 |
0.1.38-alpha | 234 | 1/19/2023 |
0.1.37-alpha | 229 | 1/19/2023 |
0.1.34-alpha | 220 | 1/18/2023 |
0.1.33-alpha | 197 | 1/15/2023 |
0.1.30-alpha | 260 | 11/21/2022 |
0.1.22-alpha | 219 | 11/19/2022 |
0.1.21-alpha | 216 | 11/19/2022 |
0.1.19-alpha | 194 | 11/19/2022 |
0.1.18-alpha | 225 | 11/18/2022 |
0.1.17-alpha | 299 | 11/14/2022 |
0.1.13-alpha | 205 | 11/13/2022 |
0.1.12-alpha | 247 | 10/31/2022 |
0.1.10-alpha | 196 | 10/28/2022 |
0.1.9-alpha | 241 | 10/27/2022 |
0.1.8-alpha | 269 | 10/27/2022 |
0.1.5-alpha | 216 | 10/27/2022 |
0.1.4-alpha | 244 | 10/27/2022 |
0.1.3-alpha | 266 | 10/26/2022 |
0.1.2-alpha | 264 | 10/25/2022 |
0.1.1-alpha | 291 | 10/25/2022 |