Replies: 1 comment 1 reply
-
Hi @wshamp, I looked through the code and I'm a little confused by certain parts. You are starting up the state.mode = .parent(ParentFeature.State())
return .merge(
.cancel(id: CancelID.stringsObservation)
.run { send in
for try await strings in await stringsClient.observeStringsChange() {
await send(.stringsChangedFromAPI(strings))
}
}
.cancellable(id: CancelID.stringsObservation, cancelInFlight: true)
) …but that still allows one final tick of the timer to go through, and further due to the re-entrancy problem I described previously, changing the mode with However, there seems like a far simpler solution to this problem. Why not just start the case .onTask:
var path = StackState<ParentFeature.Path.State>()
path.append(.child(ChildFeature.State()))
state.mode = .parent(ParentFeature.State(path: path))
return .merge (
.run { send in
for await _ in self.clock.timer(interval: .seconds(1.0)) {
await send(.timerTicked)
}
},
.run { send in
for try await strings in await stringsClient.observeStringsChange() {
await send(.stringsChangedFromAPI(.success(strings)))
}
}
.cancellable(id: CancelID.stringsObservation, cancelInFlight: true))
case .timerTicked:
state.elapsed += 1.0
print(state.elapsed)
if state.elapsed == 1.0 {
state.mode = .parent(ParentFeature.State())
return .cancel(id: CancelID.stringsObservation)
} else {
return .none
} |
Beta Was this translation helpful? Give feedback.
-
The beta discussion has been closed so I am creating a new discussion here. It seems that when you are observing the publisher of a @shared property in a child of a navigation stack it sometimes causes the effect to be retained and you get the purple warning.
Steps to reproduce:
This is kind of verbose so here is a link to a project example
TCASharedStateMemoryLeak.zip
Beta Was this translation helpful? Give feedback.
All reactions