Skip to content
Open
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
24 changes: 24 additions & 0 deletions Sources/Nodes/Internal/FlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public final class FlowController {

internal var isFlowLeakDetectionEnabled: Bool = true

#if DEBUG

private var _flowCount: Int = 0

#endif

/// Initializes a new ``FlowController`` instance to manage a collection of `Flow` instances.
public init() {}

Expand Down Expand Up @@ -68,6 +74,9 @@ public final class FlowController {
DebugInformation.FlowControllerWillAttachNotification(flowController: self, flow: flow).post()
#endif
flows.append(flow)
#if DEBUG
_flowCount += 1
#endif
flow.start()
}

Expand All @@ -84,6 +93,9 @@ public final class FlowController {
return
}
flow.end()
#if DEBUG
_flowCount -= 1
#endif
flows.removeAll { $0 === flow }
if isFlowLeakDetectionEnabled { LeakDetector.detect(flow) }
#if DEBUG
Expand Down Expand Up @@ -234,4 +246,16 @@ public final class FlowController {
public func withFlows<T>(ofType type: T.Type, perform: (_ flow: T) throws -> Void) rethrows {
try flows(ofType: type).forEach(perform)
}

#if DEBUG

deinit {
if _flowCount > 0 {
assertionFailure("""
Lifecycle Violation: Expect `Flow` instances to detach before `FlowController` is deallocated.
""")
}
}

#endif
}