Skip to content

Commit 5d10590

Browse files
committed
Cancel timers before making nil
1 parent 05d861b commit 5d10590

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Sources/sACNKit/Receiver/sACNDiscoveryReceiver.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ public class sACNDiscoveryReceiver {
306306

307307
/// Stops the main heartbeat timer.
308308
private func stopHeartbeat() {
309+
heartbeatTimer?.cancel()
309310
heartbeatTimer = nil
310311
}
311312

Sources/sACNKit/Receiver/sACNReceiverRaw.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public class sACNReceiverRaw {
237237
guard _isListening else { return }
238238
self._isListening = false
239239

240+
sampleTimer?.cancel()
240241
sampleTimer = nil
241242
stopHeartbeat()
242243

@@ -390,6 +391,7 @@ public class sACNReceiverRaw {
390391

391392
/// Stops the main heartbeat timer.
392393
private func stopHeartbeat() {
394+
heartbeatTimer?.cancel()
393395
heartbeatTimer = nil
394396
}
395397

@@ -437,6 +439,7 @@ public class sACNReceiverRaw {
437439

438440
self.beginSamplingPeriod(notify: false)
439441
} else {
442+
self.sampleTimer?.cancel()
440443
self.sampleTimer = nil
441444

442445
// notify sampling has ended

Sources/sACNKit/Source/sACNSource.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,10 @@ final public class sACNSource {
547547

548548
/// Stops this source's universe discovery heartbeat.
549549
private func stopUniverseDiscovery() {
550-
timerQueue.sync { universeDiscoveryTimer = nil }
550+
timerQueue.sync {
551+
universeDiscoveryTimer?.cancel()
552+
universeDiscoveryTimer = nil
553+
}
551554
}
552555

553556
/// Starts this source's data transmission heartbeat.
@@ -666,7 +669,10 @@ private extension sACNSource {
666669
// termination of all universes to be removed is complete
667670
if self.shouldTerminate {
668671
// the source should terminate
669-
timerQueue.sync { dataTransmitTimer = nil }
672+
timerQueue.sync {
673+
dataTransmitTimer?.cancel()
674+
dataTransmitTimer = nil
675+
}
670676

671677
sockets.forEach { _, socket in
672678
socket.stopListening()

0 commit comments

Comments
 (0)