GithubHelp home page GithubHelp logo

omermor / asyncbridge Goto Github PK

View Code? Open in Web Editor NEW
131.0 20.0 46.0 9.9 MB

Adds the new C# 5 async for older .NET 3.5 and .NET 4.0 projects.

Home Page: http://omermor.github.com/AsyncBridge/

License: Other

C# 97.11% PowerShell 2.89%

asyncbridge's Introduction

AsyncBridge provides C# 5 async and await support for pre-net45 projects.

Newly unified package (net35, net40 and sl5):
NuGet Download count

Deprecated packages:
NuGet Download count (AsyncBridge.Net35)
NuGet Download count (AsyncBridge.Portable)

Based on a gist by Daniel Grunwald. Thanks to Alex Davies for the idea! See also LICENSE.md.

AppVeyor

asyncbridge's People

Contributors

alexdavies74 avatar alphagremlin avatar jnm2 avatar omermor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asyncbridge's Issues

ConfigureAwait(false) has no effect

I'm hitting a bug where awaiting any ConfigureAwait(false) continues on the UI thread rather than a threadpool thread.

Where .NET Framework has:

[SecurityCritical]
public void UnsafeOnCompleted(Action continuation)
{
    TaskAwaiter.OnCompletedInternal(m_task, continuation, m_continueOnCapturedContext, flowExecutionContext:false);
}

Your ConfiguredTaskAwaitable<>.ConfiguredTaskAwaiter has:

public void UnsafeOnCompleted(Action continuation)
{
TaskAwaiter.OnCompletedInternal(m_task, continuation, true);
}

But your OnCompleted is correct:

public void OnCompleted(Action continuation)
{
TaskAwaiter.OnCompletedInternal(m_task, continuation, m_continueOnCapturedContext);
}

Your ConfiguredTaskAwaitable.ConfiguredTaskAwaiter has the same problem.

Looks like an obvious fix. Would you accept a PR?

Semaphore wait will block thread

When I use Semaphore in async function. It will block thread.

Is any way to implement semaphore.waitAsync(); like SemaphoreSlim in .net framework 4

MSTest is skipping your async tests for net35

Of your 26 total tests, only 3 are being run for your .NET Framework 3.5 build.

MSTest is not finding or running any async Task test methods. This makes sense since it's probably not using duck typing to run Task tests.

It's straightforward to fix by converting all the tests to (non-async) void.

(net35) System.Threading polyfill dependency incorrectly flows SynchronizationContext

For reference, this demonstrates the bug: https://github.com/jnm2/AsyncBridge/compare/sync_context_flow_bug

This differs from the .NET Framework 4.5 behavior. Example of what can go wrong:

// UI thread
await Task.Run(async () =>
{
    // Thread pool thread
    DoCPUIntensiveWork();
    await DoIOBoundWorkAsync();
    // PROBLEM: the await resumes on the UI thread, not a thread pool thread!
    DoCPUIntensiveWork(); // Ends up blocking the UI thread
});

The workaround is to await DoIOBoundWorkAsync().ConfigureAwait(false). (Once v0.3.0 is out with the fix for #7!) To be clear, ConfigureAwait(false) is better code, but it should still not be necessary.

Looks like another easy fix. The problem is, the source code for TaskParallelLibrary 1.0.2856 is not on the internet as far as I can tell. The nupkg and binaries are first committed to this repo in f97269a and had been downloaded from https://www.nuget.org/packages/rx-core/1.0.2856. I've scoured https://rx.codeplex.com/ and https://github.com/Reactive-Extensions/Rx.NET and am pretty sure they do not contain the source of System.Threading.dll from TaskParallelLibrary.

At this point it seems likely that creating a fresh net47-net35 or perhaps corefx/net35 shim from scratch in a single DLL would be cleanest.

Provide portable library support

I would have uploaded a zip file with the modified source (don't use git anymore) but found no way uploading a file so
here comes a list of the steps to perform in order to make it work in no time.

1; Create a Portable library and add all files from the .NET 4 project as links
1.1; Select .NET framework 4 and Silverlight 5 as target frameworks (Metro apps can also be selected)
2; Add a define "PORTABLE" to the AsyncBridge.Portable project
3; Solve issues with "TargetedPatchingOptOut"

Replace:
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]

With:

if !PORTABLE

    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]

endif

4; Solve issues with ThreadPool.UnsafeQueueUserWorkITem In YieldAwaitable.queueContinuation

Replace:
if (flowContext)
ThreadPool.QueueUserWorkItem(s_waitCallbackRunAction, continuation);
else
ThreadPool.UnsafeQueueUserWorkItem(s_waitCallbackRunAction, continuation);
With:
#if !PORTABLE
if (flowContext)
ThreadPool.QueueUserWorkItem(s_waitCallbackRunAction, continuation);
else
ThreadPool.UnsafeQueueUserWorkItem(s_waitCallbackRunAction, continuation);
#else
ThreadPool.QueueUserWorkItem(s_waitCallbackRunAction, continuation);
#endif

Add AsyncLocal<T>

Make net46 the no-op target, and ship a net45 binary with only AsyncLocal.

Add .editorconfig

If we have any wishes for field and variable naming conventions, we should put them in an .editorconfig and possibly a DotSettings. This will save time and trouble for contributors.

Other things to add: trimming whitespace, adding an ending line, UTF-8 without byte order mark.

Release 0.4.0?

I see that there's a milestone for 0.4.0, but there has not been any activity since 2018. Is there any chance of quickly finishing and releasing 0.4.0? I personally am interested in net20 support, which seems to be slated for 0.4.0 and at least partially implemented in the no_dependencies branch. I'm happy to assist in any way possible.

Sign Assembly

Hi,
Please sign Nuget package to easier use...
Thanks

Maintainers welcome!

Unfortunately for this library, the closest thing to an active maintainer right now is me. When @OmerMor agreed to make me a maintainer, I fixed a significant ConfigureAwait bug (#7), modernized the repo and packaging, and got the fix on NuGet. Then I started fixing the last outstanding bug I discovered (#12) which required replacing an upstream dependency. This turned out to be so much work that I didn't have time to complete it. I don't foresee having a significant amount of time to devote to this project.

If you have energy and interest, I'll do what I can to enable you to help maintain this project. I can publish AsyncBridge NuGet packages. We'll reach out to @OmerMor to ask that they make you a full maintainer. (I don't have access to repo settings yet, so I can't do this part.)

I'll try to respond to issues amid the deluge of my GitHub notifications either way.

Async Targeting Pack

Hey guys,

Just wondering what your plans are for async bridge now the targeting pack has been released? Are there any uses for the project now? Or is it simply an open source version of the targeting pack?

Cheers,
Jake

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.