diff --git a/SJSAssetExportSession/ExportSession.swift b/SJSAssetExportSession/ExportSession.swift index 508eefa..6f639da 100644 --- a/SJSAssetExportSession/ExportSession.swift +++ b/SJSAssetExportSession/ExportSession.swift @@ -7,19 +7,13 @@ public import AVFoundation -public final class ExportSession: @unchecked Sendable { - // @unchecked Sendable because progress properties are mutable, it's safe though. +public final class ExportSession: Sendable { + public let progressStream: AsyncStream - public typealias ProgressStream = AsyncStream - - public var progressStream: ProgressStream = ProgressStream(unfolding: { 0.0 }) - - private var progressContinuation: ProgressStream.Continuation? + private let progressContinuation: AsyncStream.Continuation public init() { - progressStream = AsyncStream { continuation in - progressContinuation = continuation - } + (progressStream, progressContinuation) = AsyncStream.makeStream() } public func export( @@ -49,7 +43,7 @@ public final class ExportSession: @unchecked Sendable { ) Task { [progressContinuation] in for await progress in await sampleWriter.progressStream { - progressContinuation?.yield(progress) + progressContinuation.yield(progress) } } try await sampleWriter.writeSamples() @@ -129,7 +123,7 @@ public final class ExportSession: @unchecked Sendable { ) Task { [progressContinuation] in for await progress in await sampleWriter.progressStream { - progressContinuation?.yield(progress) + progressContinuation.yield(progress) } } try await sampleWriter.writeSamples()