Skip to content

Commit

Permalink
Always run server handlers inside an async context
Browse files Browse the repository at this point in the history
  • Loading branch information
artempyanykh committed May 18, 2022
1 parent c7784ff commit 5e00d67
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/LanguageServerProtocol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,14 @@ module Server =

let requestHandling<'param, 'result> (run: 'param -> AsyncLspResult<'result>) : Delegate =
let runAsTask param ct =
let asyncLspResult = run param

let asyncContinuation =
async {
let! lspResult = asyncLspResult
// Make sure we call `run` inside an `async` block.
// Although, `run` returns an Async<...> value, it's body doesn't *have* to be all async,
// so any exceptions raised in non-async part can bubble up and kill a thread.
// Calling `run` inside an `async` block ensures that any raised exceptions will be caught and
// sent back in a response to an LSP client.
let! lspResult = run param

return
match lspResult with
Expand Down Expand Up @@ -662,4 +665,4 @@ module Client =

return ()
}
|> Async.Start
|> Async.Start

0 comments on commit 5e00d67

Please sign in to comment.