• Stars
    star
    3,295
  • Rank 13,040 (Top 0.3 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A helper library for async/await.

Logo

AsyncEx

A helper library for async/await.

Note: This README is for AsyncEx v5 (the current version). For AsyncEx v4, see here.

Supports netstandard1.3 (including .NET 4.6, .NET Core 1.0, Xamarin.iOS 10, Xamarin.Android 7, Mono 4.6, and Universal Windows 10).

NuGet Pre Release netstandard 1.3 netstandard 2.0 Code Coverage Build status

API docs

Overview - Upgrade Guide

Getting Started

Install the NuGet package.

AsyncLock

A lot of developers start using this library for AsyncLock, an async-compatible mutual exclusion mechanism. Using AsyncLock is straightforward:

private readonly AsyncLock _mutex = new AsyncLock();
public async Task UseLockAsync()
{
  // AsyncLock can be locked asynchronously
  using (await _mutex.LockAsync())
  {
    // It's safe to await while the lock is held
    await Task.Delay(TimeSpan.FromSeconds(1));
  }
}

AsyncLock also fully supports cancellation:

public async Task UseLockAsync()
{
  // Attempt to take the lock only for 2 seconds.
  var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
  
  // If the lock isn't available after 2 seconds, this will
  //  raise OperationCanceledException.
  using (await _mutex.LockAsync(cts.Token))
  {
    await Task.Delay(TimeSpan.FromSeconds(1));
  }
}

AsyncLock also has a synchronous API. This permits some threads to acquire the lock asynchronously while other threads acquire the lock synchronously (blocking the thread).

public async Task UseLockAsync()
{
  using (await _mutex.LockAsync())
  {
    await Task.Delay(TimeSpan.FromSeconds(1));
  }
}

public void UseLock()
{
  using (_mutex.Lock())
  {
    Thread.Sleep(TimeSpan.FromSeconds(1));
  }
}

Other Coordination Primitives

AsyncLock is just the beginning. The AsyncEx library contains a full suite of coordination primitives: AsyncManualResetEvent, AsyncAutoResetEvent, AsyncConditionVariable, AsyncMonitor, AsyncSemaphore, AsyncCountdownEvent, and AsyncReaderWriterLock.

More Stuff

There's quite a few other helpful types; see the docs for full details

Infrequently Asked Questions

Older Platforms

AsyncEx v4 supported .NET 4.0, Windows Store 8.1, Windows Phone Silverlight 8.0, Windows Phone Applications 8.1, and Silverlight 5.0. Support for these platforms has been dropped with AsyncEx v5.

AsyncEx v3 supported Windows Store 8.0, Windows Phone Silverlight 7.5, and Silverlight 4.0. Support for these platforms has been dropped with AsyncEx v4.

More Repositories

1

Comparers

The last comparison library you'll ever need!
C#
400
star
2

StructuredConcurrency

Structured concurrency support for C#
C#
203
star
3

Mvvm

MVVM helpers, including calculated properties and asynchronous notification tasks.
C#
132
star
4

AspNetBackgroundTasks

A component that registers "fire and forget" tasks with the ASP.NET runtime.
C#
109
star
5

Deque

Double-ended queue
C#
105
star
6

Disposables

IDisposable helper types.
C#
98
star
7

CalculatedProperties

Easy-to-use calculated properties for MVVM apps
C#
73
star
8

AsyncDiagnostics

Easy-to-use exception causality chains for async/await.
C#
61
star
9

BrowserBoss

Easily script browsers.
C#
55
star
10

Try

The Try monad (Error/Exceptional monad) for C#
C#
44
star
11

ConnectedProperties

Dynamically attach properties to (almost) any object instance.
C#
41
star
12

Guids

Helper types for creating and interpreting GUIDs.
C#
27
star
13

Presentations

Repository for presentations
C#
27
star
14

PegLeg

A PEG parser for C#, using code generators
C#
22
star
15

CrossDomainSingleton

An AppDomain-aware, thread-safe singleton that ensures only one instance exists in the entire application.
C#
22
star
16

LocalTelemetry

Local dashboards for telemetry collection.
18
star
17

Docs

Documentation of various and sundry matters
16
star
18

grounded-chatgpt

ChatGPT, but grounded in custom data
C#
16
star
19

HashAlgorithms

CRC calculation for .NET
C#
16
star
20

DependencyInjection

Helpers for Microsoft.Extensions.DependencyInjection.
C#
15
star
21

ArraySegments

A library for slicing and dicing arrays (without copying).
C#
13
star
22

Scripts

Misc single-file scripts and utilities
C#
13
star
23

ArcDb

An ACID .NET relational database
12
star
24

Mvvm.CalculatedProperties

Automatically raise PropertyChanged in MVVM applications.
C#
11
star
25

Cancellation

Types to assist with cancellation handling.
C#
11
star
26

DisplayProfiles

An application that saves and restores display monitor layouts.
C#
10
star
27

Mvvm.Core

Basic MVVM helpers.
C#
10
star
28

AsyncCTPUtil

Utility code originally distributed as part of the Async CTP
C#
10
star
29

ProjProps

A dotnet tool that displays project properties.
C#
10
star
30

Logging

Library for using scopes with Microsoft.Extensions.Logging.
C#
10
star
31

AsyncEx.Testing

Helper types for writing unit tests for asynchronous code.
C#
9
star
32

ProducerConsumerStream

A producer/consumer collection of bytes with a Stream-based API.
C#
8
star
33

OptionParsing

Flexible command-line parsing library
C#
8
star
34

BuildTools

Miscellaneous tools for building .NET Core libraries.
7
star
35

UniformResourceIdentifiers

Standard-compliant URI encoders and parsers
C#
6
star
36

iterjs

ES6 library for working with iterables and iterators
JavaScript
5
star
37

Quicly

An implementation of IETF QUIC in .NET
C#
4
star
38

StrongNamer

Simple app that strong-names NuGet packages.
C#
3
star
39

AsyncUnitTests

Helpers for async unit testing.
C#
3
star
40

blog-stephencleary-dotcom

blog.stephencleary.com
HTML
2
star
41

Hosting

.NET Generic Host for UI applications
C#
2
star
42

Collections.Async

Async-compatible producer/consumer collections.
2
star
43

comments.stephencleary.com

Comments for stephencleary.com.
JavaScript
2
star
44

stephencleary-dotcom

HTML
1
star
45

LoggerProviderHelpers

Helper types for implementing Microsoft's ILoggerProvider.
1
star
46

ARC

A simple dynamic language. Like JavaScript, but better!
C#
1
star
47

DockerLifetime

A .NET Core lifetime service for Docker containers
1
star
48

Hymnals

Public domain hymnals
LilyPond
1
star
49

glob

GitHub Action that finds files using globs (wildcards)
JavaScript
1
star
50

Presentations-IntermediateAsync

Sample code for presentation given at GRDevDay 2013-03-02
1
star