Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor deinit assertions #890

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Refactor deinit assertions
tinder-cfuller committed Feb 23, 2025
commit f23e16a57517ddf766b667f2ace54e538ca88c04
8 changes: 5 additions & 3 deletions Sources/Nodes/Core/AbstractContext.swift
Original file line number Diff line number Diff line change
@@ -139,13 +139,15 @@ open class _BaseContext: Context { // swiftlint:disable:this type_name
try workerController.withWorkers(ofType: type, perform: perform)
}

#if DEBUG

deinit {
#if DEBUG
if isActive {
assertionFailure("Lifecycle Violation: Expected `AbstractContext` to deactivate before it is deallocated.")
assertionFailure("Lifecycle Violation: Expected `AbstractContext` to deactivate before it is deallocated")
}
#endif
}

#endif
}

/**
8 changes: 5 additions & 3 deletions Sources/Nodes/Core/AbstractFlow.swift
Original file line number Diff line number Diff line change
@@ -279,13 +279,15 @@ open class AbstractFlow<ContextInterfaceType, ViewControllerType>: Flow {
try flowController.withFlows(ofType: type, perform: perform)
}

#if DEBUG

deinit {
#if DEBUG
if _isStarted {
assertionFailure("Lifecycle Violation: Expected `AbstractFlow` to end before it is deallocated.")
assertionFailure("Lifecycle Violation: Expected `AbstractFlow` to end before it is deallocated")
}
#endif
}

#endif
}

// swiftlint:enable period_spacing
8 changes: 5 additions & 3 deletions Sources/Nodes/Core/AbstractWorker.swift
Original file line number Diff line number Diff line change
@@ -70,13 +70,15 @@ open class _BaseWorker: Worker { // swiftlint:disable:this type_name
isWorking = false
}

#if DEBUG

deinit {
#if DEBUG
if isWorking {
assertionFailure("Lifecycle Violation: Expected `AbstractWorker` to stop before it is deallocated.")
assertionFailure("Lifecycle Violation: Expected `AbstractWorker` to stop before it is deallocated")
}
#endif
}

#endif
}

/**
8 changes: 5 additions & 3 deletions Sources/Nodes/Internal/WorkerController.swift
Original file line number Diff line number Diff line change
@@ -93,16 +93,18 @@ public final class WorkerController {
try workers(ofType: type).forEach(perform)
}

#if DEBUG

deinit {
#if DEBUG
for worker: Worker in workers {
if worker.isWorking {
assertionFailure("""
Lifecycle Violation: Expected `Worker` to stop before `WorkerController` is deallocated.
Lifecycle Violation: Expected `Worker` to stop before `WorkerController` is deallocated
""")
}
LeakDetector.detect(worker)
}
#endif
}

#endif
}