From eeb9361b594b5e0f6a14a0c16ca730bf4790dbb3 Mon Sep 17 00:00:00 2001 From: Ruiyang Sun Date: Mon, 22 Apr 2024 12:20:23 +0800 Subject: [PATCH] fix(BidirectionalStream): fix nested stream will cause nested error (#5) --- .../SyncStream/BidirectionalAsyncStream.swift | 22 +++++++++++-------- .../SyncStream/BidirectionalSyncStream.swift | 22 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Sources/SyncStream/BidirectionalAsyncStream.swift b/Sources/SyncStream/BidirectionalAsyncStream.swift index 74b6bbc..f7db129 100644 --- a/Sources/SyncStream/BidirectionalAsyncStream.swift +++ b/Sources/SyncStream/BidirectionalAsyncStream.swift @@ -218,15 +218,19 @@ public extension BidirectionalAsyncStream { finished = true - let filename = (fileName as NSString).lastPathComponent - let terminated = Terminated( - fileName: fileName, - functionName: functionName, - lineNumber: lineNumber, - columnNumber: columnNumber, - error: error - ) - state = .error(terminated) + if let error = (error as? Terminated) { + state = .error(error) + } else { + let filename = (fileName as NSString).lastPathComponent + let terminated = Terminated( + fileName: fileName, + functionName: functionName, + lineNumber: lineNumber, + columnNumber: columnNumber, + error: error + ) + state = .error(terminated) + } await yieldSemaphore.signal() } diff --git a/Sources/SyncStream/BidirectionalSyncStream.swift b/Sources/SyncStream/BidirectionalSyncStream.swift index 6d49be1..bfc1332 100644 --- a/Sources/SyncStream/BidirectionalSyncStream.swift +++ b/Sources/SyncStream/BidirectionalSyncStream.swift @@ -262,15 +262,19 @@ public extension BidirectionalSyncStream { finished = true - let filename = (fileName as NSString).lastPathComponent - let terminated = Terminated( - fileName: fileName, - functionName: functionName, - lineNumber: lineNumber, - columnNumber: columnNumber, - error: error - ) - state = .error(terminated) + if let error = (error as? Terminated) { + state = .error(error) + } else { + let filename = (fileName as NSString).lastPathComponent + let terminated = Terminated( + fileName: fileName, + functionName: functionName, + lineNumber: lineNumber, + columnNumber: columnNumber, + error: error + ) + state = .error(terminated) + } yieldSemaphore.signal() }