mirror of
https://github.com/samsonjs/SJSAssetExportSession.git
synced 2026-04-27 14:57:46 +00:00
Use AsyncStream.makeStream to fix Sendable conformance
This commit is contained in:
parent
8e46d79376
commit
64edbb2ccd
1 changed files with 6 additions and 12 deletions
|
|
@ -7,19 +7,13 @@
|
||||||
|
|
||||||
public import AVFoundation
|
public import AVFoundation
|
||||||
|
|
||||||
public final class ExportSession: @unchecked Sendable {
|
public final class ExportSession: Sendable {
|
||||||
// @unchecked Sendable because progress properties are mutable, it's safe though.
|
public let progressStream: AsyncStream<Float>
|
||||||
|
|
||||||
public typealias ProgressStream = AsyncStream<Float>
|
private let progressContinuation: AsyncStream<Float>.Continuation
|
||||||
|
|
||||||
public var progressStream: ProgressStream = ProgressStream(unfolding: { 0.0 })
|
|
||||||
|
|
||||||
private var progressContinuation: ProgressStream.Continuation?
|
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
progressStream = AsyncStream { continuation in
|
(progressStream, progressContinuation) = AsyncStream<Float>.makeStream()
|
||||||
progressContinuation = continuation
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func export(
|
public func export(
|
||||||
|
|
@ -49,7 +43,7 @@ public final class ExportSession: @unchecked Sendable {
|
||||||
)
|
)
|
||||||
Task { [progressContinuation] in
|
Task { [progressContinuation] in
|
||||||
for await progress in await sampleWriter.progressStream {
|
for await progress in await sampleWriter.progressStream {
|
||||||
progressContinuation?.yield(progress)
|
progressContinuation.yield(progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try await sampleWriter.writeSamples()
|
try await sampleWriter.writeSamples()
|
||||||
|
|
@ -129,7 +123,7 @@ public final class ExportSession: @unchecked Sendable {
|
||||||
)
|
)
|
||||||
Task { [progressContinuation] in
|
Task { [progressContinuation] in
|
||||||
for await progress in await sampleWriter.progressStream {
|
for await progress in await sampleWriter.progressStream {
|
||||||
progressContinuation?.yield(progress)
|
progressContinuation.yield(progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try await sampleWriter.writeSamples()
|
try await sampleWriter.writeSamples()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue