Replies: 2 comments 2 replies
-
It could be the case that I guess you'll need to do this: do! (RavenDb.saveChangesAsync session) |> Async.StartAsTask More information here -> https://learn.microsoft.com/en-us/dotnet/fsharp/tutorials/async#core-concepts. |
Beta Was this translation helpful? Give feedback.
-
I'm not entirely sure as I have not thoroughly evaluated the provided code, nor have I tested anything, but I believe it could be fixed by moving the let handler session: HttpHandler =
choose
[ other handlers.. ]
let sessionHandler documentStore: HttpHandler =
fun next ctx ->
task {
let session = RavenDb.createSession documentStore
let! result = (handler session) next ctx // use `let!` to await the result
do! RavenDb.saveChangesAsync session
return result // use a regular return, as the result has been previously awaited
}
let webApp documentStore = HttpHandlers.sessionHandler documentStore |
Beta Was this translation helpful? Give feedback.
-
I'm trying to build a handler that opens and closes a document database (RavenDB) session, and calls other handlers in between.
However, when I try the above code, the database complains about
saveChangedAsync
being called concurrently:Any idea how to call other handlers and properly "await" the result before continuing in the task expression?
Beta Was this translation helpful? Give feedback.
All reactions