How to return a Task implementing IAsyncActionFilter in F#?

Viewed 73

it's me again

I'm implementing the IAsyncActionFilter interface and I have the following:

type UserExistsFilter =

    interface IAsyncActionFilter with

        member this.OnActionExecutionAsync(context: ActionExecutingContext, next: ActionExecutionDelegate) =
            let task = next.Invoke
            task

However I got the following error:

This expression was expected to have type 'Task' but here has type 'unit -> Task<ActionExecutedContext>'

What am I missing?

1 Answers

The following worked for me:

type UserExistsFilter =

    interface IAsyncActionFilter with

        member this.OnActionExecutionAsync(context: ActionExecutingContext, next: ActionExecutionDelegate) =
            async {
                let task = next.Invoke()
                return task
            }
            |> Async.StartAsTask :> Task
Related