How to unwrap an async
See original GitHub issueI just upgraded from Cvdm.ErrorHandling to this.
In Cvdm.ErrorHandling, I could unwrap an Async<Result<User, string>> by using let! operator without piping into any of the AsyncResult or Result module conversion functions.
// tryGetUser = int -> Async<Result<User, string>>
let! myResult = tryGetUser(1) // returns a Result<User, string>
Now this fails because it’s trying to look at the result type. But in this case, I don’t want to fully unwrap it to be just a User – I actually want it to be a Result<User, string> so that I can do some custom logic for the error case.
Is there a way to do this? I’m looking through the AsyncResult module, but I don’t see anything relevant.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (1 by maintainers)
Top Results From Across the Web
c# - await await vs Unwrap()
@hatcyl Unwrap returns a new task that represents the inner task of a Task<Task> . It will be able to return such a...
Read more >TaskExtensions.Unwrap Method (System.Threading.Tasks)
Unwrap (Task<Task>). Creates a proxy Task that represents the asynchronous operation of a Task<Task> (C#) or Task (Of Task) (Visual Basic).
Read more >How to: Unwrap a Nested Task | Microsoft Learn
Unwrap the inner task. Task<string> t3 = DoWorkAsync().ContinueWith((s) => DoMoreWorkAsync()).Unwrap(); // Outputs "More work completed.
Read more >Where should value unwrapping be performed? #15
In #8, we agreed that when you yield a promise: async function* g() { yield new Promise(...); } The promise should be unwrapped...
Read more >Task.Unwrap() - A useful proxy to avoid inner Task inside a Task
The Task that is returned by 'Unwrap' includes all the cancelation token request and exception handling (the proxy is doing the job of ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Would you consider adding this helper function to the AsyncResult module?
For a more concrete example, you can an async CE inline and do something like this: