Mac OSX Launcher: Cancel stream that can cause high cpu load on router stop.

This commit is contained in:
meeh
2018-09-30 11:02:28 +00:00
parent 2233f7f47b
commit b5497ef72e

View File

@ -36,17 +36,23 @@ class LogViewerViewController : NSTabViewItem {
let output = self.outputPipe?.fileHandleForReading.availableData
let outputString = String(data: output!, encoding: String.Encoding.utf8) ?? ""
DispatchQueue.main.async(execute: {
let workTask = DispatchWorkItem {
let previousOutput = self.textFieldView?.string ?? ""
let nextOutput = previousOutput + "\n" + outputString
self.textFieldView?.string = nextOutput
let range = NSRange(location:nextOutput.characters.count,length:0)
self.textFieldView?.scrollRangeToVisible(range)
}
DispatchQueue.main.async(execute: workTask)
// When router stop, stop the stream as well. If not it will go wild and create high cpu load
RouterManager.shared().eventManager.listenTo(eventName: "router_stop", action: {
NSLog("Time to cancel stream!")
workTask.cancel()
})
self.outputPipe?.fileHandleForReading.waitForDataInBackgroundAndNotify()
}