From 1bb83f28403e8ac9194a696990b8913e736d55e2 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Wed, 23 Oct 2024 10:37:02 +1300 Subject: [PATCH] update async channels (#188) --- Networking/Package.swift | 2 +- Networking/Sources/Networking/Stream.swift | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Networking/Package.swift b/Networking/Package.swift index 36e29a4d..ee9b929a 100644 --- a/Networking/Package.swift +++ b/Networking/Package.swift @@ -20,7 +20,7 @@ let package = Package( .package(url: "https://github.com/apple/swift-log.git", from: "1.6.0"), .package(url: "https://github.com/apple/swift-certificates.git", from: "1.5.0"), .package(url: "https://github.com/apple/swift-testing.git", branch: "0.10.0"), - .package(url: "https://github.com/gh123man/Async-Channels.git", from: "1.0.0"), + .package(url: "https://github.com/gh123man/Async-Channels.git", from: "1.0.2"), ], targets: [ .target( diff --git a/Networking/Sources/Networking/Stream.swift b/Networking/Sources/Networking/Stream.swift index 85adefaa..03aaca32 100644 --- a/Networking/Sources/Networking/Stream.swift +++ b/Networking/Sources/Networking/Stream.swift @@ -71,17 +71,17 @@ final class Stream: Sendable, StreamProtocol { if data.isEmpty { return } - // TODO: backpressure handling - // https://github.com/gh123man/Async-Channels/issues/11 - Task { - await channel.send(data) + + if !channel.syncSend(data) { + logger.warning("stream \(id) is full") + // TODO: backpressure handling } } // initiate stream close public func close(abort: Bool = false) { if status != .open { - logger.warning("Trying to close stream \(stream.id) in status \(status)") + logger.warning("Trying to close stream \(id) in status \(status)") return } status = abort ? .aborted : .closed