Giter Club home page Giter Club logo

configureawait's Introduction

ConfigureAwait.Fody

Chat on Gitter NuGet Status

Configure async code's ConfigureAwait at a global level.

This is an add-in for Fody

It is expected that all developers using Fody become a Patron on OpenCollective. See Licensing/Patron FAQ for more information.

Usage

See also Fody usage.

NuGet package

Install the ConfigureAwait.Fody NuGet package and update the Fody NuGet package:

PM> Install-Package Fody
PM> Install-Package ConfigureAwait.Fody

The Install-Package Fody is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.

How to use it

By default, ConfigureAwait.Fody doesn't change any code. Set a configure await value at the assembly, class, or method level.

  • [assembly: Fody.ConfigureAwait(false)] - Assembly level
  • [Fody.ConfigureAwait(false)] - Class or method level

Explicitly configured awaiters will not be overwritten by the weaver, allowing exceptions to the Assembly / Class / Method level setting.

Add to FodyWeavers.xml

Add <ConfigureAwait/> to FodyWeavers.xml

<Weavers>
  <ConfigureAwait/>
</Weavers>

It is also possible set the default ContinueOnCapturedContext in the xml config:

<Weavers>
  <ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

Example

Before code

using Fody;

[ConfigureAwait(false)]
public class MyAsyncLibrary
{
    public async Task MyMethodAsync()
    {
        await Task.Delay(10);
        await Task.Delay(20).ConfigureAwait(true);
    }

    public async Task AnotherMethodAsync()
    {
        await Task.Delay(30);
    }
}

What gets compiled

public class MyAsyncLibrary
{
    public async Task MyMethodAsync()
    {
        await Task.Delay(10).ConfigureAwait(false);
        await Task.Delay(20).ConfigureAwait(true);
    }

    public async Task AnotherMethodAsync()
    {
        await Task.Delay(30).ConfigureAwait(false);
    }
}

Icon

Created by Dmitry Baranovskiy from The Noun Project.

configureawait's People

Contributors

dependabot-preview[bot] avatar simoncropp avatar dependabot[bot] avatar dependabot-support avatar distantcam avatar blankensteiner avatar danielchalmers avatar dessix avatar tom-englert avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.