1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00

Do not send API requests when stopped

This commit is contained in:
Tae Won Ha 2017-12-09 17:41:54 +01:00
parent 2027a10251
commit c51ed64fa9
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 22 additions and 9 deletions

View File

@ -52,8 +52,11 @@ public class Connection {
locked(with: condition) { condition.broadcast() }
}
}
self.stopped = true
self.session.disconnectAndStop()
locked(with: self.sessionLock) {
self.stopped = true
self.session.disconnectAndStop()
}
}
@discardableResult
@ -64,6 +67,8 @@ public class Connection {
expectsReturnValue: Bool)
-> MsgPackRpc.Response {
let packed = pack(
[
.uint(UInt64(type)),
@ -74,18 +79,25 @@ public class Connection {
)
guard expectsReturnValue else {
self.session.write(packed)
return self.nilResponse(with: msgid)
return locked(with: self.sessionLock) {
if !self.stopped {
self.session.write(packed)
}
return self.nilResponse(with: msgid)
}
}
let condition = NSCondition()
locked(with: self.conditionsLock) { self.conditions[msgid] = condition }
if self.stopped {
return self.nilResponse(with: msgid)
}
locked(with: self.sessionLock) {
if self.stopped {
return
}
self.session.write(packed)
self.session.write(packed)
}
locked(with: condition) {
while !self.stopped && self.responses[msgid] == nil && condition.wait(until: Date(timeIntervalSinceNow: 5)) {}
@ -113,6 +125,7 @@ public class Connection {
private var conditions: [UInt32: NSCondition] = [:]
private let conditionsLock = NSRecursiveLock()
private let sessionLock = NSRecursiveLock()
private var stopped = false
private func nilResponse(with msgid: UInt32) -> MsgPackRpc.Response {

View File

@ -180,8 +180,8 @@ extension NvimView {
public func stop() {
self.bridgeLogger.hr()
self.agent.quit()
self.nvim.disconnect()
self.agent.quit()
gui.async {
self.waitForNeoVimToQuit()