Files
SwiftLint/Source/SwiftLintFramework/Extensions/QueuedPrint.swift
T
JP Simard 8c171458f8 make QueuedPrint.swift compile on Linux
by adding an explicit `import Dispatch` and disabling the `atexit_b` call
on Linux. This just means that we won't be able to guarantee that the print()
buffer will have been flushed at program exit. Hopefully this doesn't
cause too many issues.
2016-12-11 14:04:49 -08:00

50 lines
940 B
Swift

//
// QueuedPrint.swift
// SwiftLint
//
// Created by JP Simard on 11/17/15.
// Copyright © 2015 Realm. All rights reserved.
//
import Dispatch
import Foundation
private let outputQueue: DispatchQueue = {
let queue = DispatchQueue(
label: "io.realm.swiftlint.outputQueue",
qos: .userInteractive,
target: .global(qos: .userInteractive)
)
#if !os(Linux)
atexit_b {
queue.sync(flags: .barrier) {}
}
#endif
return queue
}()
/**
A thread-safe version of Swift's standard print().
- parameter object: Object to print.
*/
public func queuedPrint<T>(_ object: T) {
outputQueue.async {
print(object)
}
}
/**
A thread-safe, newline-terminated version of fputs(..., stderr).
- parameter string: String to print.
*/
public func queuedPrintError(_ string: String) {
outputQueue.async {
fflush(stdout)
fputs(string + "\n", stderr)
}
}