-
-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Code looked like this:
extension DataChannel {
/// Create a passthrough `DataChannel` that invokes a closure on read and write.
public static func tap(
channel: DataChannel,
onRead: @Sendable @escaping (Data) async -> Void,
onWrite: @Sendable @escaping (Data) async -> Void
) -> DataChannel {
let writeHandler: DataChannel.WriteHandler = {
await onWrite($0)
try await channel.writeHandler($0)
}
var iterator = channel.dataSequence.makeAsyncIterator()
let dataStream = AsyncStream<Data> {
let data = await iterator.next()
if let data = data {
await onRead(data)
}
return data
}
return DataChannel(writeHandler: writeHandler,
dataSequence: dataStream)
}
}The issue is iterator is not Sendable and that AsyncStream block is @Senable. This is trivial to "fix" with a nonisolated(unsafe), but I'm not 100% sure that is actually a safe thing to do and would require some thought.
Metadata
Metadata
Assignees
Labels
No labels