Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/CodableDatastore/Datastore/Datastore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extension Datastore {
if let progressHandler {
warmupProgressHandlers.append(progressHandler)
}
let warmupTask = Task {
let warmupTask = Task(name: "CodableDatastore.Datastore.warmupIfNeeded(progressHandler:) - Datastore: \(key)") {
try await persistence._withTransaction(
actionName: "Migrate \(key) Instances",
options: []
Expand Down
2 changes: 1 addition & 1 deletion Sources/CodableDatastore/Helpers/AsyncFileReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AsyncFileReader: @unchecked Sendable {

init(contentsOf url: URL) {
self.url = url
self.readerTask = Task(name: "AsyncFileReader") { await self.startReading() }
self.readerTask = Task(name: "CodableDatastore.AsyncFileReader.init(contentsOf:) - File: \(url.lastPathComponent)") { await self.startReading() }
}

func startReading() async {
Expand Down
17 changes: 15 additions & 2 deletions Sources/CodableDatastore/Helpers/Swift6.1+Compatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@
//

#if compiler(<6.2)
extension Task where Failure == Never {
extension Task {
@discardableResult
init(name: String?, priority: TaskPriority? = nil, operation: sending @escaping @isolated(any) () async -> Success) {
init(
name: String?,
priority: TaskPriority? = nil,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated(any) () async -> Success
) where Failure == Never {
self.init(priority: priority, operation: operation)
}

@discardableResult
init(
name: String?,
priority: TaskPriority? = nil,
@_inheritActorContext @_implicitSelfCapture operation: sending @escaping @isolated(any) () async throws -> Success
) where Failure == any Error {
self.init(priority: priority, operation: operation)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct AsyncThrowingBackpressureStream<Element: Sendable>: Sendable {
}
}
} onCancel: {
Task { await cancelPendingRead() }
Task(name: "CodableDatastore.AsyncThrowingBackpressureStream.consumeNext()") { await cancelPendingRead() }
}
}

Expand Down Expand Up @@ -119,7 +119,7 @@ struct AsyncThrowingBackpressureStream<Element: Sendable>: Sendable {
continuation.resume(throwing: CancellationError())
return
}
Task {
Task(name: "CodableDatastore.AsyncThrowingBackpressureStream.Continuation.yield()") {
await stateMachine.provide(.success(value), in: continuation)
}
} as Void
Expand All @@ -133,7 +133,7 @@ struct AsyncThrowingBackpressureStream<Element: Sendable>: Sendable {
guard let stateMachine else { continuation.resume(throwing: CancellationError())
return
}
Task {
Task(name: "CodableDatastore.AsyncThrowingBackpressureStream.Continuation.finish(throwing:)") {
if let error {
await stateMachine.provide(.failure(error), in: continuation)
} else {
Expand All @@ -150,7 +150,7 @@ struct AsyncThrowingBackpressureStream<Element: Sendable>: Sendable {
stateMachine = StateMachine()

let continuation = Continuation(stateMachine: stateMachine)
Task {
Task(name: "CodableDatastore.AsyncThrowingBackpressureStream.init(provider:)") {
do {
try await provider(continuation)
try await continuation.finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension DiskPersistence.Datastore {
}

deinit {
Task { [id, datastore] in
Task(name: "CodableDatastore.DiskPersistence.Datastore.Index.deinit - Index: \(id)") { [id, datastore] in
await datastore.invalidate(id)
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ extension DiskPersistence.Datastore.Index {
get async throws {
if let manifestTask { return try await manifestTask.value }

let loader = Task {
let loader = Task(name: "CodableDatastore.DiskPersistence.Datastore.Index.manifest - Index: \(id)") {
if let _manifest { return _manifest }

let manifest = try await DatastoreIndexManifest(contentsOf: manifestURL, id: id.manifestID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ extension DiskPersistence.Datastore {
self.datastore = datastore
self.id = id
self.blocksReaderTask = blocks.map { blocks in
Task {
Task(name: "CodableDatastore.DiskPersistence.Datastore.Page.init(...) - Page: \(id)") {
MultiplexedAsyncSequence(base: AnyReadableSequence(blocks))
}
}
self.isPersisted = blocks == nil
}

deinit {
Task { [id, datastore] in
Task(name: "CodableDatastore.DiskPersistence.Datastore.Page.deinit - Page: \(id)") { [id, datastore] in
await datastore.invalidate(id)
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ extension DiskPersistence.Datastore.Page {
return try await blocksReaderTask.value
}

let readerTask = Task {
let readerTask = Task(name: "CodableDatastore.DiskPersistence.Datastore.Page.blocks - Page: \(id)") {
try await performRead(sequence: readableSequence)
}
isPersisted = true
Expand Down Expand Up @@ -192,7 +192,7 @@ actor MultiplexedAsyncSequence<Base: AsyncSequence & Sendable>: AsyncSequence wh

let lastTask: Task<Element?, any Error>? = cachedEntries.last

let newTask = Task {
let newTask = Task(name: "CodableDatastore.MultiplexedAsyncSequence.subscript(_:)") {
/// Make sure previous iteration finished before sourcing the next one.
_ = try? await lastTask?.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension DiskPersistence.Datastore {
}

deinit {
Task { [id, datastore] in
Task(name: "CodableDatastore.DiskPersistence.Datastore.RootObject.deinit - RootObject: \(id)") { [id, datastore] in
await datastore.invalidate(id)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ extension DiskPersistence.Datastore {
// print("🤷 Cache Miss: Root \(identifier)")
let rootObject = RootObject(datastore: self, id: identifier)
trackedRootObjects[identifier] = WeakValue(rootObject)
Task { await snapshot.persistence.cache(rootObject) }
Task(name: "CodableDatastore.DiskPersistence.Datastore.rootObject(for:).cache - Datastore: \(id)") { await snapshot.persistence.cache(rootObject) }
return rootObject
}

func adopt(rootObject: RootObject) {
trackedRootObjects[rootObject.id] = WeakValue(rootObject)
Task { await snapshot.persistence.cache(rootObject) }
Task(name: "CodableDatastore.DiskPersistence.Datastore.adopt(rootObject:).cache - Datastore: \(id)") { await snapshot.persistence.cache(rootObject) }
}

func invalidate(_ identifier: RootObject.ID) {
Expand All @@ -166,13 +166,13 @@ extension DiskPersistence.Datastore {
// print("🤷 Cache Miss: Index \(identifier)")
let index = Index(datastore: self, id: identifier)
trackedIndexes[identifier] = WeakValue(index)
Task { await snapshot.persistence.cache(index) }
Task(name: "CodableDatastore.DiskPersistence.Datastore.index(for:).cache - Datastore: \(id)") { await snapshot.persistence.cache(index) }
return index
}

func adopt(index: Index) {
trackedIndexes[index.id] = WeakValue(index)
Task { await snapshot.persistence.cache(index) }
Task(name: "CodableDatastore.DiskPersistence.Datastore.adopt(index:).cache - Datastore: \(id)") { await snapshot.persistence.cache(index) }
}

func invalidate(_ identifier: Index.ID) {
Expand All @@ -194,13 +194,13 @@ extension DiskPersistence.Datastore {
// print("🤷 Cache Miss: Page \(identifier.page)")
let page = Page(datastore: self, id: identifier)
trackedPages[identifier.withoutManifest] = WeakValue(page)
Task { await snapshot.persistence.cache(page) }
Task(name: "CodableDatastore.DiskPersistence.Datastore.page(for:).cache - Datastore: \(id)") { await snapshot.persistence.cache(page) }
return page
}

func adopt(page: Page) {
trackedPages[page.id.withoutManifest] = WeakValue(page)
Task { await snapshot.persistence.cache(page) }
Task(name: "CodableDatastore.DiskPersistence.Datastore.adopt(page:).cache - Datastore: \(id)") { await snapshot.persistence.cache(page) }
}

func invalidate(_ identifier: Page.ID) {
Expand Down Expand Up @@ -262,7 +262,7 @@ extension DiskPersistence.Datastore {
nextObserverID += 1
observers[id] = observer
observer.onTermination = { _ in
Task {
Task(name: "CodableDatastore.DiskPersistence.Datastore.register(observer:).onTermination - Datastore: \(self.id), Observer: \(id)") {
await self.unregisterObserver(for: id)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ extension DiskPersistence {
self.options = options
self.transactionIndex = transactionIndex

let workDidFinishPromise = Promise(name: "DiskPersistence.Transaction.workDidFinish - \"\(actionName ?? "")\"")
let transactionDidPersistPromise = Promise(name: "DiskPersistence.Transaction.transactionDidPersist - \"\(actionName ?? "")\"")
let workDidFinishPromise = Promise(name: "CodableDatastore.DiskPersistence.Transaction.init(...).workDidFinish - Action: \"\(actionName ?? "")\"")
let transactionDidPersistPromise = Promise(name: "CodableDatastore.DiskPersistence.Transaction.init(...).transactionDidPersist - Action: \"\(actionName ?? "")\"")

self.workDidFinishResult = workDidFinishPromise.future
self.transactionDidPersistResult = transactionDidPersistPromise.future
Expand Down Expand Up @@ -107,7 +107,7 @@ extension DiskPersistence {
/// Persist the work that was just completed to signal to the next transaction that it can start, but check for the requested timing option first. ``persist()`` takes care of signaling when the persistence is finished.
if options.contains(.collateWrites) {
/// If we are skipping immediate writes, kick off persistence in a separate task.
Task {
Task(name: "CodableDatastore.DiskPersistence.Transaction.run()") {
try await self.persist()
}
} else {
Expand Down