- Notifications
You must be signed in to change notification settings - Fork 2.1k
Support F# async in actions #5570
Description
Support F# async like the Task based async in actions.
So an action like the following can be used OOTB.
member this.About () = async { let! msg = getDescription () this.ViewData.["Message"] <- msg return this.View() }I added an example aspnet project with both F# async and current workaround actions.
Example is based on dotnet new -l fsharp -t web template in preview4, but is the same for all sdk versions (preview2 etc)
The f# async Home/About doesnt work (async class is converted as string => {}), converting as Task works in Home/About2
The workaround is to call Async.StartAsTask before returning the FSharpAsync, so is converted as Task.
How to implement that.
Like xunit does, recognize the result is FSharpAsync and invoke Async.StartAsTask (ref xunit commit to add f# async support xunit/xunit@a2aa665 )
In previous aspnet was possibile to use an ActionResult.
Speaking with @davidfowl he directed me into ObjectMethodExecutor class.
It should not give runtime performance penality (f# or c#), because it's done at initialization step also for normal Task, so at runtime just use a different delegate configured in ObjectMethodExecutor (in GetCoerceMethodCallExpression?)
/cc @panesofglass