From e25f2af224e302911c1239b398d6827bddc6e5b5 Mon Sep 17 00:00:00 2001 From: Jamie <2119834+jamieQ@users.noreply.github.com> Date: Thu, 4 Dec 2025 05:46:30 -0600 Subject: [PATCH] [refactor]: use sequence- rather than iterator-based iteration --- .../SecretAgentKit/SocketController.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Sources/Packages/Sources/SecretAgentKit/SocketController.swift b/Sources/Packages/Sources/SecretAgentKit/SocketController.swift index 8ab7976..7839037 100644 --- a/Sources/Packages/Sources/SecretAgentKit/SocketController.swift +++ b/Sources/Packages/Sources/SecretAgentKit/SocketController.swift @@ -37,15 +37,13 @@ public struct SocketController { port = SocketPort(path: path) fileHandle = FileHandle(fileDescriptor: port.socket, closeOnDealloc: true) Task { @MainActor [fileHandle, sessionsContinuation, logger] in - // Create the iterator before triggering the notification to + // Create the sequence before triggering the notification to // ensure it will not be missed. - let connectionAvailableIterator = NotificationCenter.default - .notifications(named: .NSFileHandleConnectionAccepted) - .makeAsyncIterator() + let connectionAcceptedNotifications = NotificationCenter.default.notifications(named: .NSFileHandleConnectionAccepted) fileHandle.acceptConnectionInBackgroundAndNotify() - while let notification = await connectionAvailableIterator.next() { + for await notification in connectionAcceptedNotifications { logger.debug("Socket controller accepted connection") guard let new = notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle else { continue } let session = Session(fileHandle: new) @@ -85,15 +83,13 @@ extension SocketController { provenance = SigningRequestTracer().provenance(from: fileHandle) (messages, messagesContinuation) = AsyncStream.makeStream() Task { @MainActor [messagesContinuation, logger] in - // Create the iterator before triggering the notification to + // Create the sequence before triggering the notification to // ensure it will not be missed. - let dataAvailableIterator = NotificationCenter.default - .notifications(named: .NSFileHandleDataAvailable, object: fileHandle) - .makeAsyncIterator() + let dataAvailableNotifications = NotificationCenter.default.notifications(named: .NSFileHandleDataAvailable, object: fileHandle) fileHandle.waitForDataInBackgroundAndNotify() - while let _ = await dataAvailableIterator.next() { + for await _ in dataAvailableNotifications { let data = fileHandle.availableData guard !data.isEmpty else { logger.debug("Socket controller received empty data, ending continuation.")