Skip to content

Commit

Permalink
Merge pull request #357 from PierreYvesR/CancellationTokenDispose
Browse files Browse the repository at this point in the history
Remoting.Client: dispose of the CancellationTokenRegistration when done
  • Loading branch information
Zaid-Ajaj authored Jan 8, 2024
2 parents 92cabee + 77f7abe commit 35ec835
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Fable.Remoting.Client/Http.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ module Http =
| Some f -> f xhr
| _ -> ignore()

token.Register(fun _ ->
xhr.abort()
cancel(System.OperationCanceledException(token))
) |> ignore
let cancellationTokenRegistration =
token.Register(fun _ ->
xhr.abort()
cancel(System.OperationCanceledException(token))
)

// set the headers, must be after opening the request
for (key, value) in req.Headers do
Expand All @@ -70,6 +71,7 @@ module Http =
xhr.onreadystatechange <- fun _ ->
match xhr.readyState with
| ReadyState.Done when not token.IsCancellationRequested ->
(cancellationTokenRegistration :> System.IDisposable).Dispose()
xhr |> resultMapper |> resolve
| _ -> ignore()

Expand Down

0 comments on commit 35ec835

Please sign in to comment.