Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket CPU efficiency improvements. #711

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/FSharp.Formatting.CommandTool/BuildCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,15 @@ module Serve =
tag.Replace("{{PORT}}", string port)


let mutable signalHotReload = false

let signalHotReload = new System.Threading.ManualResetEvent(false);

let socketHandler (webSocket : WebSocket) _ = socket {
while true do
signalHotReload.WaitOne() |> ignore
signalHotReload.Reset() |> ignore
let emptyResponse = [||] |> ByteSegment
//not sure what this was needed for
//do!
// refreshEvent.Publish
// |> Control.Async.AwaitEvent
// |> Suave.Sockets.SocketOp.ofAsync
//do! webSocket.send Text (ByteSegment (Encoding.UTF8.GetBytes "refreshed")) true
if signalHotReload then
printfn "Triggering hot reload on the client"
do! webSocket.send Close emptyResponse true
signalHotReload <- false
printfn "Triggering hot reload on the client"
do! webSocket.send Close emptyResponse true
}

let startWebServer outputDirectory localPort =
Expand Down Expand Up @@ -842,7 +836,7 @@ type CoreBuildOptions(watch) =
if runDocContentPhase2() then
regenerateSearchIndex()
)
Serve.signalHotReload <- true
Serve.signalHotReload.Set() |> ignore
}
|> Async.Start
)
Expand All @@ -860,7 +854,7 @@ type CoreBuildOptions(watch) =
if runGeneratePhase2() then
regenerateSearchIndex()
)
Serve.signalHotReload <- true
Serve.signalHotReload.Set() |> ignore
}
|> Async.Start
)
Expand Down