From 95760764a5af45f8ca4d9bda6cb86d44dc8294a7 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sun, 3 Aug 2025 01:04:53 +0800 Subject: [PATCH] fix --- Sources/Punchnet/SDLSuperClient.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Sources/Punchnet/SDLSuperClient.swift b/Sources/Punchnet/SDLSuperClient.swift index 350de99..4688351 100644 --- a/Sources/Punchnet/SDLSuperClient.swift +++ b/Sources/Punchnet/SDLSuperClient.swift @@ -98,13 +98,16 @@ actor SDLSuperClient { } // --MARK: 心跳机制 -// group.addTask { -// while !Task.isCancelled { -// await self.ping() -// try await Task.sleep(nanoseconds: 5 * 1_000_000_000) -// } -// NSLog("[SDLSuperClient] heartbeat cancelled") -// } + group.addTask { + while true { + try Task.checkCancellation() + await self.ping() + try Task.checkCancellation() + try await Task.sleep(nanoseconds: 5 * 1_000_000_000) + try Task.checkCancellation() + } + NSLog("[SDLSuperClient] heartbeat cancelled") + } try await group.waitForAll() NSLog("[SDLSuperClient] group closed")