Skip to content

Commit

Permalink
cleanup shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Nov 19, 2020
1 parent 86fe5aa commit 2e18e60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ module ModelImpl =
ignore <| nvim.grid_resize gridui.Id gridui.GridWidth gridui.GridHeight

let Detach() =
nvim.stop(0)
states.Shutdown(0)
if nvim.isRemote then
states.Shutdown(0)

let UpdateUICapabilities() =
let opts = hashmap[]
Expand Down
14 changes: 11 additions & 3 deletions neovim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ open System.Runtime.InteropServices
let inline private trace fmt = trace "neovim.process" fmt

let private default_notify (e: Request) =
failwithf "%A" e
task { return () }

let private default_call (e: Request) =
failwithf "%A" e
task { return {result=Result.Error(box "not connected")} }

type NvimIO =
| Disconnected
Expand All @@ -43,7 +43,7 @@ type Nvim() as nvim =
let mutable m_events = None
let mutable m_io = Disconnected
let mutable m_disposables = []
let m_cancelSrc = new CancellationTokenSource()
let mutable m_cancelSrc = Unchecked.defaultof<CancellationTokenSource>

member __.Id = Guid.NewGuid()

Expand Down Expand Up @@ -97,6 +97,7 @@ type Nvim() as nvim =
| Disconnected, None -> ()
| _ -> failwith "neovim: already started"

m_cancelSrc <- new CancellationTokenSource()
let io = nvim.createIO opts

let serverExitCode() =
Expand Down Expand Up @@ -254,6 +255,12 @@ type Nvim() as nvim =

member __.stop (timeout: int) =

match m_io with
| Disconnected -> ()
| _ ->

trace "stopping"

// Send cancellation signal
m_cancelSrc.Cancel()
m_cancelSrc.Dispose()
Expand All @@ -275,6 +282,7 @@ type Nvim() as nvim =
stream.Dispose()
| Disconnected -> ()

m_cancelSrc <- null
m_io <- Disconnected
m_events <- None
m_notify <- default_notify
Expand Down
6 changes: 4 additions & 2 deletions states.fs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ let backgroundCompositionToString =
| Acrylic -> "acrylic"
| Transparent -> "transparent"

let Shutdown code = _appLifetime.Value.Shutdown code
let Shutdown code =
try _appLifetime.Value.Shutdown code
with _ -> ()

let get_crash_info() =
_crashcode, _errormsgs
Expand Down Expand Up @@ -274,7 +276,7 @@ let msg_dispatch =
_errormsgs.Add err
| Exit ->
trace "rpc" "shutting down application lifetime"
_appLifetime.Value.Shutdown()
Shutdown 0
| Crash code ->
trace "rpc" "neovim crashed with code %d" code
_crashcode <- code
Expand Down

0 comments on commit 2e18e60

Please sign in to comment.