From 18702bdbaa67ce6c546d36068c0d659e624181c8 Mon Sep 17 00:00:00 2001 From: khoi <6994441+khoi@users.noreply.github.com> Date: Tue, 17 Feb 2026 23:02:42 +0700 Subject: [PATCH] Replace remaining Task.sleep calls with ContinuousClock sleep --- supacode/App/AppLoadingView.swift | 2 +- supacode/App/CommandKeyObserver.swift | 2 +- supacode/Features/App/Reducer/AppFeature.swift | 2 +- .../Features/Repositories/Reducer/RepositoriesFeature.swift | 6 +++--- .../Repositories/Views/NotificationPopoverButton.swift | 2 +- .../Repositories/Views/PullRequestChecksPopoverButton.swift | 2 +- .../Views/ToolbarNotificationsPopoverButton.swift | 2 +- .../TabBar/Views/TerminalTabBarTrailingAccessories.swift | 4 ++-- .../Terminal/TabBar/Views/TerminalTabsRowView.swift | 2 +- .../Terminal/Views/GhosttySurfaceSearchOverlay.swift | 2 +- supacode/Infrastructure/Ghostty/GhosttySurfaceBridge.swift | 2 +- supacode/Infrastructure/Ghostty/GhosttySurfaceView.swift | 2 +- supacodeTests/GithubCLIClientTests.swift | 4 ++-- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/supacode/App/AppLoadingView.swift b/supacode/App/AppLoadingView.swift index 877b0830..e517dc47 100644 --- a/supacode/App/AppLoadingView.swift +++ b/supacode/App/AppLoadingView.swift @@ -42,7 +42,7 @@ struct AppLoadingView: View { private func cycleMessages() async { while !Task.isCancelled { - try? await Task.sleep(for: .seconds(1.8)) + try? await ContinuousClock().sleep(for: .seconds(1.8)) await MainActor.run { withAnimation(.easeInOut(duration: 0.25)) { messageIndex = (messageIndex + 1) % Self.messages.count diff --git a/supacode/App/CommandKeyObserver.swift b/supacode/App/CommandKeyObserver.swift index c0612784..c23efe25 100644 --- a/supacode/App/CommandKeyObserver.swift +++ b/supacode/App/CommandKeyObserver.swift @@ -55,7 +55,7 @@ final class CommandKeyObserver { if isDown { holdTask = Task { - try? await Task.sleep(for: Self.holdDelay) + try? await ContinuousClock().sleep(for: Self.holdDelay) guard !Task.isCancelled else { return } isPressed = true } diff --git a/supacode/Features/App/Reducer/AppFeature.swift b/supacode/Features/App/Reducer/AppFeature.swift index aa05ff25..db204b9c 100644 --- a/supacode/Features/App/Reducer/AppFeature.swift +++ b/supacode/Features/App/Reducer/AppFeature.swift @@ -112,7 +112,7 @@ struct AppFeature { .send(.repositories(.refreshWorktrees)), .run { send in while !Task.isCancelled { - try? await Task.sleep(for: .seconds(30)) + try? await ContinuousClock().sleep(for: .seconds(30)) guard !Task.isCancelled else { return } await send(.repositories(.refreshWorktrees)) } diff --git a/supacode/Features/Repositories/Reducer/RepositoriesFeature.swift b/supacode/Features/Repositories/Reducer/RepositoriesFeature.swift index 0c3e77c5..04c9aaa0 100644 --- a/supacode/Features/Repositories/Reducer/RepositoriesFeature.swift +++ b/supacode/Features/Repositories/Reducer/RepositoriesFeature.swift @@ -1349,7 +1349,7 @@ struct RepositoriesFeature { return .cancel(id: CancelID.toastAutoDismiss) case .success: return .run { send in - try? await Task.sleep(for: .seconds(2.5)) + try? await ContinuousClock().sleep(for: .seconds(2.5)) await send(.dismissToast) } .cancellable(id: CancelID.toastAutoDismiss, cancelInFlight: true) @@ -1369,7 +1369,7 @@ struct RepositoriesFeature { let repositoryRootURL = worktree.repositoryRootURL let worktreeIDs = repository.worktrees.map(\.id) return .run { send in - try? await Task.sleep(for: .seconds(2)) + try? await ContinuousClock().sleep(for: .seconds(2)) await send( .worktreeInfoEvent( .repositoryPullRequestRefresh( @@ -1542,7 +1542,7 @@ struct RepositoriesFeature { state.inFlightPullRequestRefreshRepositoryIDs.removeAll() return .run { send in while !Task.isCancelled { - try? await Task.sleep(for: githubIntegrationRecoveryInterval) + try? await ContinuousClock().sleep(for: githubIntegrationRecoveryInterval) guard !Task.isCancelled else { return } diff --git a/supacode/Features/Repositories/Views/NotificationPopoverButton.swift b/supacode/Features/Repositories/Views/NotificationPopoverButton.swift index 891a110b..a2fa19ae 100644 --- a/supacode/Features/Repositories/Views/NotificationPopoverButton.swift +++ b/supacode/Features/Repositories/Views/NotificationPopoverButton.swift @@ -47,7 +47,7 @@ struct NotificationPopoverButton: View { } closeTask?.cancel() closeTask = Task { @MainActor in - try? await Task.sleep(for: .milliseconds(150)) + try? await ContinuousClock().sleep(for: .milliseconds(150)) if !Task.isCancelled { isPresented = false } diff --git a/supacode/Features/Repositories/Views/PullRequestChecksPopoverButton.swift b/supacode/Features/Repositories/Views/PullRequestChecksPopoverButton.swift index 4d0d88cf..01068a31 100644 --- a/supacode/Features/Repositories/Views/PullRequestChecksPopoverButton.swift +++ b/supacode/Features/Repositories/Views/PullRequestChecksPopoverButton.swift @@ -54,7 +54,7 @@ struct PullRequestChecksPopoverButton: View { } closeTask?.cancel() closeTask = Task { @MainActor in - try? await Task.sleep(for: .milliseconds(150)) + try? await ContinuousClock().sleep(for: .milliseconds(150)) if !Task.isCancelled { isPresented = false } diff --git a/supacode/Features/Repositories/Views/ToolbarNotificationsPopoverButton.swift b/supacode/Features/Repositories/Views/ToolbarNotificationsPopoverButton.swift index 69fc7cd6..0d64040d 100644 --- a/supacode/Features/Repositories/Views/ToolbarNotificationsPopoverButton.swift +++ b/supacode/Features/Repositories/Views/ToolbarNotificationsPopoverButton.swift @@ -89,7 +89,7 @@ struct ToolbarNotificationsPopoverButton: View { } closeTask?.cancel() closeTask = Task { @MainActor in - try? await Task.sleep(for: .milliseconds(150)) + try? await ContinuousClock().sleep(for: .milliseconds(150)) if !Task.isCancelled { isPresented = false } diff --git a/supacode/Features/Terminal/TabBar/Views/TerminalTabBarTrailingAccessories.swift b/supacode/Features/Terminal/TabBar/Views/TerminalTabBarTrailingAccessories.swift index 4eab5586..88edb937 100644 --- a/supacode/Features/Terminal/TabBar/Views/TerminalTabBarTrailingAccessories.swift +++ b/supacode/Features/Terminal/TabBar/Views/TerminalTabBarTrailingAccessories.swift @@ -139,7 +139,7 @@ struct TerminalTabBarTrailingAccessories: View { openTask?.cancel() openTask = Task { @MainActor in // Intentional delay so clicks on + don't get interrupted by the hover UI. - try? await Task.sleep(for: .milliseconds(350)) + try? await ContinuousClock().sleep(for: .milliseconds(350)) guard isHoveringButton || isHoveringPopover else { return } // Prevent showing while the user is in the middle of a click-drag/click-hold. guard NSEvent.pressedMouseButtons == 0 else { return } @@ -153,7 +153,7 @@ struct TerminalTabBarTrailingAccessories: View { closeTask?.cancel() closeTask = Task { @MainActor in // Allow time to move from button into popover without it flashing closed. - try? await Task.sleep(for: .milliseconds(350)) + try? await ContinuousClock().sleep(for: .milliseconds(350)) guard !(isHoveringButton || isHoveringPopover) else { return } isHoverPopoverPresented = false } diff --git a/supacode/Features/Terminal/TabBar/Views/TerminalTabsRowView.swift b/supacode/Features/Terminal/TabBar/Views/TerminalTabsRowView.swift index 772234ab..b0c15860 100644 --- a/supacode/Features/Terminal/TabBar/Views/TerminalTabsRowView.swift +++ b/supacode/Features/Terminal/TabBar/Views/TerminalTabsRowView.swift @@ -104,7 +104,7 @@ struct TerminalTabsRowView: View { } } Task { @MainActor in - try? await Task.sleep(for: .seconds(TerminalTabBarMetrics.closeAnimationDuration)) + try? await ContinuousClock().sleep(for: .seconds(TerminalTabBarMetrics.closeAnimationDuration)) if let selectedId = manager.selectedTabId { withAnimation { scrollReader.scrollTo(selectedId) diff --git a/supacode/Features/Terminal/Views/GhosttySurfaceSearchOverlay.swift b/supacode/Features/Terminal/Views/GhosttySurfaceSearchOverlay.swift index 96913249..51c4652e 100644 --- a/supacode/Features/Terminal/Views/GhosttySurfaceSearchOverlay.swift +++ b/supacode/Features/Terminal/Views/GhosttySurfaceSearchOverlay.swift @@ -150,7 +150,7 @@ struct GhosttySurfaceSearchOverlay: View { let text = needle searchTask = Task { @MainActor in do { - try await Task.sleep(for: .milliseconds(300)) + try await ContinuousClock().sleep(for: .milliseconds(300)) } catch { return } diff --git a/supacode/Infrastructure/Ghostty/GhosttySurfaceBridge.swift b/supacode/Infrastructure/Ghostty/GhosttySurfaceBridge.swift index 50e46787..3aacf8c7 100644 --- a/supacode/Infrastructure/Ghostty/GhosttySurfaceBridge.swift +++ b/supacode/Infrastructure/Ghostty/GhosttySurfaceBridge.swift @@ -217,7 +217,7 @@ final class GhosttySurfaceBridge { } else { state.progressState = report.state progressResetTask = Task { @MainActor [weak self] in - try? await Task.sleep(for: .seconds(15)) + try? await ContinuousClock().sleep(for: .seconds(15)) guard let self, !Task.isCancelled else { return } self.state.progressState = nil self.state.progressValue = nil diff --git a/supacode/Infrastructure/Ghostty/GhosttySurfaceView.swift b/supacode/Infrastructure/Ghostty/GhosttySurfaceView.swift index 99ff09c3..5daf5b4a 100644 --- a/supacode/Infrastructure/Ghostty/GhosttySurfaceView.swift +++ b/supacode/Infrastructure/Ghostty/GhosttySurfaceView.swift @@ -698,7 +698,7 @@ final class GhosttySurfaceView: NSView, Identifiable { let nextDelay: TimeInterval = if let delay { delay * 2 } else { 0.05 } Task { @MainActor in if let delay { - try? await Task.sleep(for: .seconds(delay)) + try? await ContinuousClock().sleep(for: .seconds(delay)) } guard let window = view.window else { moveFocus(to: view, from: previous, delay: nextDelay) diff --git a/supacodeTests/GithubCLIClientTests.swift b/supacodeTests/GithubCLIClientTests.swift index 3f7444d5..8eec680e 100644 --- a/supacodeTests/GithubCLIClientTests.swift +++ b/supacodeTests/GithubCLIClientTests.swift @@ -67,7 +67,7 @@ struct GithubCLIClientTests { await probe.recordLoginCall() _ = await probe.beginGhCall() do { - try await Task.sleep(for: .milliseconds(80)) + try await ContinuousClock().sleep(for: .milliseconds(80)) let stdout = graphQLResponse(for: arguments) await probe.endGhCall() return ShellOutput(stdout: stdout, stderr: "", exitCode: 0) @@ -116,7 +116,7 @@ struct GithubCLIClientTests { ) } do { - try await Task.sleep(for: .milliseconds(40)) + try await ContinuousClock().sleep(for: .milliseconds(40)) let stdout = graphQLResponse(for: arguments) await probe.endGhCall() return ShellOutput(stdout: stdout, stderr: "", exitCode: 0) -- 2.51.2