What's the difference between doing the following:
async Task<T> method(){ var r = await dynamodb.GetItemAsync(...) return r.Item; }
vs
async Task<T> method(){ var task = dynamodb.GetItemAsync(...) return task.Result.Item; }
In my case, for some reason, only the second works. The first one never seems to end.
await asynchronously unwraps the result of your task, whereas just using Result would block until the task had completed.
The call to the async method starts an asynchronous task. However, because no Await operator is applied, the program continues without waiting for the task to complete. In most cases, that behavior isn't expected.
A significant benefit of the async/await pattern in languages that support it is that asynchronous, non-blocking code can be written, with minimal overhead, and looking almost like traditional synchronous, blocking code.
Async methods can have the following return types: Task, for an async method that performs an operation but returns no value. Task<TResult>, for an async method that returns a value. void , for an event handler.
await
asynchronously unwraps the result of your task, whereas just using Result would block until the task had completed.
See this explanantion from Jon Skeet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With