Question: How to use with async / await?
See original GitHub issueQuestion: is there a way to call Match with async / await? Related to #26
I have:
public async Task<OneOf<Foo, None>> HandleAsync(GetFooQuery query)
{
var foo = await GetByIdAsync(query.FooId);
return foo.Match<OneOf<Foo, None>>(
f => GetCustomerNameForFooAsync(f).Result,
_ => new None());
}
private async Task<OneOf<Foo, None>> GetByIdAsync(FooId fooId)
{ ...
private async Task<Foo> GetCustomerNameForFooAsync(Foo foo)
{ ...
but the .Result
on the end is a bit icky (edit: and is not asyncronous!). Would be nice if I could do something like:
public async Task<OneOf<Foo, None>> HandleAsync(GetFooQuery query)
{
var foo = await GetByIdAsync(query.FooId);
return foo.Match<OneOf<Foo, None>>(
async f => await GetCustomerNameForFooAsync(f),
_ => new None());
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Interview question: async & await (C#)
Q : What is the purpose of async / await keywords? These keywords allow writing asynchronous non-blocking code in a synchronous fashion.
Read more >C# Async/Await Interview Questions And Answers (2023)
This comprehensive article covers a wide range of C# async-await interview questions that will test your understanding of the async-await ...
Read more >Javascript Async/Await: Javascript Interview questions #10
Hello everyone, in this tutorial we will learn about how to use async functions, awaiting async functions, and the importance of async /...
Read more >20 Async/Await Interview Questions and Answers - CLIMB
Async /Await Interview Questions and Answers · 1. Can you explain what asynchronous programming is? · 2. How does async/await help with performance ......
Read more >Top 25 Async Await Interview Questions and Answers
Discover essential Async Await interview questions and answers for JavaScript developers in our comprehensive guide, designed to help you confidently ...
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
Hi Matt
I think the cleanest way to write it with the current lib is if you get liberal with
async
:Thanks for the reply Harry.
Yep, that works, it’s the same suggestion you made last time. My bad - I missed your comment
//you'll get a warning about it not being async, but ignore it
.I’m pedantic about not having compiler warnings so I stuck with the ugly Task.FromResult and then edited my message to get rid of the question altogether.