Draft for AwaitableResult<void> and Result<void> #268
+273
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, DotNext lacks support for Result Types that don't hold values, but instead only indicate success or failure, smiliar to Rust's
Result<(), io::Error>
for example. This draft aims to provide that functionality. It providesActionResult
Type that representsResult<void>
static ActionResult.Try()
Function that executes a potentially error throwing function and catches those errors (if they occur) within anActionResult
AwaitableResult
Type that representsAwaitableResult<void>
ActionResult
Type andstatic ActionResult.Try()
Function:AwaitableResult
Type:The aim of these additions is 1) to give the user the option to write a strong API that tells the consumer "This function might fail (but not throw Errors)" and 2) to give the user a way of handling exceptions without try catch blocks.
Both 1) and 2) are currently only possible if the function in question returns an actual value in the form of
Result<T>
orResult<T, TError>
, but not if the function is a non-returningAction
.To Do's:
new ActionResult()
constructor andnew ActionResult(Exception e)
in favor of something likestatic ActionResult.Success
andstatic ActionResult.Error(Exception e)
.Action.TryInvoke()
just like the existingFunc<T>.TryInvoke()
should be added as well.