You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public TryAsync<MyResponse> RequestAsync(Guid id)
{
var result = TryFindAsync(id); //Returns a TryOptionAsync<DbResponse>
return TryAsync( result.Match<DbResponse, MyResponse>(
p => new MyResponse(p.Id, p.Name),
async () => {
await DoSomethingAsync();
return new MyResponse(id, "hdhd");
},
raise<MyResponse>
));
}
The above works as long as the None path doesnt have the async/await. But i wondered how this should work if some of the methods have an function within it that requires and await?
To explain what I'm trying to do.
I've got a function that returns a TryOptionAsync. In case it has a result I want to map the value to a different object and return that. In case of the None I want to create a new object and return that and in case of an exception, I just want to pass on the exception.
In my use case the none path requires an async method to be called.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The above works as long as the None path doesnt have the async/await. But i wondered how this should work if some of the methods have an function within it that requires and await?
To explain what I'm trying to do.
I've got a function that returns a TryOptionAsync. In case it has a result I want to map the value to a different object and return that. In case of the None I want to create a new object and return that and in case of an exception, I just want to pass on the exception.
In my use case the none path requires an async method to be called.
Beta Was this translation helpful? Give feedback.
All reactions