Remove unused code from Core module.

This commit is contained in:
Brent Simmons 2024-03-20 22:06:43 -07:00
parent f0b8b10b2d
commit 0d5021b25f
3 changed files with 0 additions and 166 deletions

View File

@ -11,12 +11,6 @@ import Foundation
public typealias VoidBlock = () -> Void
public typealias VoidCompletionBlock = VoidBlock
/// Call a VoidCompletionBlock on the main thread.
/// - Parameter block: The block to call.
public func callVoidCompletionBlock(_ block: @escaping VoidCompletionBlock) {
DispatchQueue.main.async(execute: block)
}
public typealias VoidResult = Result<Void, Error>
public typealias VoidResultCompletionBlock = (VoidResult) -> Void

View File

@ -1,33 +0,0 @@
//
// MainThreadBlockOperation.swift
// RSCore
//
// Created by Brent Simmons on 1/16/20.
// Copyright © 2020 Ranchero Software, LLC. All rights reserved.
//
import Foundation
/// Run a block of code as an operation.
///
/// This also serves as a simple example implementation of MainThreadOperation.
public final class MainThreadBlockOperation: MainThreadOperation {
// MainThreadOperation
public var isCanceled = false
public var id: Int?
public var operationDelegate: MainThreadOperationDelegate?
public var name: String?
public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock?
private let block: VoidBlock
public init(block: @escaping VoidBlock) {
self.block = block
}
public func run() {
block()
informOperationDelegateOfCompletion()
}
}

View File

@ -1,127 +0,0 @@
//
// ManagedResourceFile.swift
// RSCore
//
// Created by Maurice Parker on 9/13/19.
// Copyright © 2020 Ranchero Software, LLC. All rights reserved.
//
import Foundation
public final class ManagedResourceFile: NSObject, NSFilePresenter {
private var isDirty = false {
didSet {
queueSaveToDiskIfNeeded()
}
}
private var isLoading = false
private let fileURL: URL
private let operationQueue: OperationQueue
private var saveQueue: CoalescingQueue
private let loadCallback: () -> Void
private let saveCallback: () -> Void
public var saveInterval: TimeInterval = 5.0 {
didSet {
saveQueue.performCallsImmediately()
saveQueue = CoalescingQueue(name: "ManagedResourceFile Save Queue", interval: saveInterval)
}
}
public var presentedItemURL: URL? {
return fileURL
}
public var presentedItemOperationQueue: OperationQueue {
return operationQueue
}
public init(fileURL: URL, load: @escaping () -> Void, save: @escaping () -> Void) {
self.fileURL = fileURL
self.loadCallback = load
self.saveCallback = save
saveQueue = CoalescingQueue(name: "ManagedResourceFile Save Queue", interval: saveInterval)
operationQueue = OperationQueue()
operationQueue.qualityOfService = .userInteractive
operationQueue.maxConcurrentOperationCount = 1
super.init()
NSFileCoordinator.addFilePresenter(self)
}
public func presentedItemDidChange() {
guard !isDirty else { return }
DispatchQueue.main.async {
self.load()
}
}
public func savePresentedItemChanges(completionHandler: @escaping (Error?) -> Void) {
saveIfNecessary()
completionHandler(nil)
}
public func relinquishPresentedItem(toReader reader: @escaping ((() -> Void)?) -> Void) {
saveQueue.isPaused = true
reader() {
self.saveQueue.isPaused = false
}
}
public func relinquishPresentedItem(toWriter writer: @escaping ((() -> Void)?) -> Void) {
saveQueue.isPaused = true
writer() {
self.saveQueue.isPaused = false
}
}
public func markAsDirty() {
if !isLoading {
isDirty = true
}
}
public func queueSaveToDiskIfNeeded() {
saveQueue.add(self, #selector(saveToDiskIfNeeded))
}
public func load() {
isLoading = true
loadCallback()
isLoading = false
}
public func saveIfNecessary() {
saveQueue.performCallsImmediately()
}
public func resume() {
NSFileCoordinator.addFilePresenter(self)
}
public func suspend() {
NSFileCoordinator.removeFilePresenter(self)
}
deinit {
NSFileCoordinator.removeFilePresenter(self)
}
}
private extension ManagedResourceFile {
@objc func saveToDiskIfNeeded() {
if isDirty {
isDirty = false
saveCallback()
}
}
}