Oakrey.Async
4.0.0
dotnet add package Oakrey.Async --version 4.0.0
NuGet\Install-Package Oakrey.Async -Version 4.0.0
<PackageReference Include="Oakrey.Async" Version="4.0.0" />
<PackageVersion Include="Oakrey.Async" Version="4.0.0" />
<PackageReference Include="Oakrey.Async" />
paket add Oakrey.Async --version 4.0.0
#r "nuget: Oakrey.Async, 4.0.0"
#:package Oakrey.Async@4.0.0
#addin nuget:?package=Oakrey.Async&version=4.0.0
#tool nuget:?package=Oakrey.Async&version=4.0.0
Oakrey.Async
Oakrey.Async provides small helpers for common asynchronous workflows in .NET: async event invocation, semaphore-based locking, timeout-linked cancellation tokens, parallel task execution, and explicit context switching.
Features
AsyncLockwrapsSemaphoreSlimacquisition in disposable and async-disposable releasers.SemaphoreSlimExtensionsaddsAcquireandAcquireAsynchelpers with idempotent release behavior.Taskerruns synchronous and asynchronous action/function batches in parallel.AsyncEventHandlerExtensionsinvokes multicast async handlers and converts synchronous handler failures into faulted tasks.TimeoutCancellationTokenSourcecreates linked cancellation token sources withCancelAfterwithout leaking an internal timeout source.ContextSwitchTaskandContextSwitchAwaitablesupport explicit thread-pool context switching for custom async workflows.
Installation
dotnet add package Oakrey.Async
Package Manager Console:
Install-Package Oakrey.Async
Examples
Use an async lock:
SemaphoreSlim semaphore = new(1, 1);
using (await AsyncLock.LockAsync(semaphore, cancellationToken))
{
await SaveAsync(cancellationToken);
}
Use the semaphore extension:
await using (await semaphore.AcquireAsync(cancellationToken))
{
await ProcessAsync(cancellationToken);
}
Run work in parallel:
bool allSucceeded = await Tasker.ParallelTaskerAsync(
[
token => ValidateAsync(token),
token => SendAsync(token)
], cancellationToken);
Invoke async event handlers:
public event AsyncEventHandler<EventArgs>? Completed;
await Completed.InvokeAsync(this, EventArgs.Empty, cancellationToken);
Create a timeout-linked token:
using CancellationTokenSource cts = TimeoutCancellationTokenSource.CreateTimeoutLinkedTokenSource(
TimeSpan.FromSeconds(10),
cancellationToken);
Notes
AsyncLockandSemaphoreSlimExtensions.Releaserrelease only once, even if disposed repeatedly.Tasker.ParallelTasker(Func<bool>[])returnstrueonly when every function returnstrue; an empty set returnstrueby normal all-of semantics.TimeoutCancellationTokenSourcereturns the linkedCancellationTokenSource; dispose it when the operation is finished.
Requirements
- .NET 11 or higher
Project Information
- Author: Oakrey
- Company: Oakrey (Website)
- License: MIT
- Repository: Git Repository
- Project URL: NuGet
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Oakrey.Async:
| Package | Downloads |
|---|---|
|
Oakrey.AT
Project AT is a .NET library for interacting with AT command-based devices. It provides a rich set of features for audio control, call management, SMS handling, phonebook operations, and eCall support. Designed for extensibility and ease of use, it is a tool for developers working on telecommunication and IoT applications. |
|
|
Oakrey.HardwareManager.Plugin.Base
Package Description |
|
|
OakreyHardwareManager.Plugin.Base
Oakrey Hardware Manager Plugin Base |
GitHub repositories
This package is not used by any popular GitHub repositories.