before the great git rework
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import HelderServices
|
||||
|
||||
/// The project note in memory; records every write.
|
||||
final class FakeNotes: NotesServicing, @unchecked Sendable {
|
||||
private let state: Locked<(stored: String, writes: [String], failWrites: Bool)>
|
||||
|
||||
init(_ stored: String = "") {
|
||||
state = Locked((stored, [], false))
|
||||
}
|
||||
|
||||
var writes: [String] { state.current.writes }
|
||||
var onDisk: String { state.current.stored }
|
||||
|
||||
var failWrites: Bool {
|
||||
get { state.current.failWrites }
|
||||
set { state.mutate { $0.failWrites = newValue } }
|
||||
}
|
||||
|
||||
/// Another program rewrote the note file.
|
||||
func setOnDisk(_ text: String) { state.mutate { $0.stored = text } }
|
||||
|
||||
func read() async -> String { state.current.stored }
|
||||
|
||||
func write(_ text: String) async throws {
|
||||
try state.mutate { state in
|
||||
if state.failWrites { throw CocoaError(.fileWriteNoPermission) }
|
||||
state.writes.append(text)
|
||||
state.stored = text
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user