Javascript:
In the javascript async programming started with callbacks and was later replaced by promises. An important benefits of promises is that it has two "channels" : one for data and one for errors.
Java 8 :
Java version of the javascript promise is CompletableFuture.
C# :
Asyncrony is essential for activities that are potentially blocking, such as web access. The async and await keywords in C# are the heart of async programming.
Asynchronous methods that you define using the async keyword are referred to as async methods. Three things to note in the signature:
- The method has an async modifier.
- The return type is Task or Task
. Here, it is Task because the return statement returns an integer. - The method name ends in "Async."
Async methods are intended to be non-blocking operations. An await expression in an async method dosen't block the current thread while the awated task is running. If an async method doesn’t use an await operator to mark a suspension point, the method executes as a synchronous.async TaskAccessTheWebAsync();
Most async methods return a Task or Task
The current method which dosen't return Task or Task
For the task that dosen't return value, you can call Task.Wait.
Exceptions:
If you await a task-returning async method that causes an exception, the await operator rethrows the exception.
If you await a task-returning async method that's canceled, the await operator rethrows an OperationCanceledException.
Best Practice:
- Prefer async Task methods over async void methods.
- Don't mix the blocking and async code to prevent deadlock
- Use ConfigureAwait(false) when you can.
Reference :
- Async programming in javascript and java 8, https://www.foreach.be/blog/parallel-and-asynchronous-programming-in-java-8
- Async, await concept in c#, https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/
- Best Practices, https://msdn.microsoft.com/en-us/magazine/jj991977.aspx
Comments
Post a Comment