For reference, the onRecieve modifier is executing every 3 seconds when the timer publishing interval is set to 3 seconds:
.onReceive(timer) { _ in
print("got here: \(Date())")
withAnimation(nucleusAnimation) {
print("animation got here: \(Date())")
nucleusRadius = Double.random(in: minSize...maxSize)
}
}
got here: 2024-10-27 14:05:58 +0000
animation got here: 2024-10-27 14:05:58 +0000
got here: 2024-10-27 14:06:01 +0000
animation got here: 2024-10-27 14:06:01 +0000
got here: 2024-10-27 14:06:04 +0000
animation got here: 2024-10-27 14:06:04 +0000
got here: 2024-10-27 14:06:07 +0000
animation got here: 2024-10-27 14:06:07 +0000
got here: 2024-10-27 14:06:10 +0000
animation got here: 2024-10-27 14:06:10 +0000
In addition, changing the timer instantiaton as follows, which appears to be more correct, did not change the CPU use:
.onReceive(Timer.publish(every: 1, on: .main, in: .common).autoconnect()) { output in
withAnimation(nucleusAnimation) {
nucleusRadius = Double.random(in: minSize...maxSize)
}
}