- Notifications
You must be signed in to change notification settings - Fork2.1k
Support F# async in actions #5570
Description
Support F#async like theTask based async in actions.
So an action likethe following can be used OOTB.
memberthis.About()=async{let!msg= getDescription() this.ViewData.["Message"]<- msgreturn this.View()}
I added anexample aspnet project with both F# async and current workaround actions.
Example is based ondotnet new -l fsharp -t web template inpreview4, but is the same for all sdk versions (preview2 etc)
The f# asyncHome/About doesnt work (async class is converted as string =>{}), converting asTask works inHome/About2
The workaround is to callAsync.StartAsTask before returning theFSharpAsync, so is converted asTask.
How to implement that.
Like xunit does, recognize the result isFSharpAsync and invokeAsync.StartAsTask (ref xunit commit to add f# async supportxunit/xunit@a2aa665 )
In previous aspnet was possibile to use anActionResult.
Speaking with@davidfowl he directed me intoObjectMethodExecutor class.
It should not give runtime performance penality (f# or c#), because it's done at initialization step also for normalTask, so at runtime just use a different delegate configured inObjectMethodExecutor (inGetCoerceMethodCallExpression?)