removed unwanted bar now with waveforms, major updates and enhancements
This commit is contained in:
@@ -135,6 +135,33 @@ enum WaveformBatch {
|
||||
}
|
||||
}
|
||||
|
||||
/// Blocking decoders and admission waits must not occupy Swift's cooperative executor.
|
||||
/// Cancellation is captured explicitly because GCD blocks have no Swift task context.
|
||||
enum WaveformWorker {
|
||||
private final class Cancellation: @unchecked Sendable {
|
||||
private let lock = NSLock()
|
||||
private var value = false
|
||||
var isCancelled: Bool { lock.lock();defer { lock.unlock() };return value }
|
||||
func cancel() { lock.lock();value = true;lock.unlock() }
|
||||
}
|
||||
static func run<T: Sendable>(_ operation: @escaping @Sendable (@escaping @Sendable () -> Bool) throws -> T) async throws -> T {
|
||||
let cancellation = Cancellation()
|
||||
return try await withTaskCancellationHandler(operation: {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
DispatchQueue.global(qos:.utility).async {
|
||||
do {
|
||||
if cancellation.isCancelled { throw CancellationError() }
|
||||
let result = try operation { cancellation.isCancelled }
|
||||
if cancellation.isCancelled { throw CancellationError() }
|
||||
continuation.resume(returning:result)
|
||||
} catch { continuation.resume(throwing:error) }
|
||||
}
|
||||
}
|
||||
},onCancel:{ cancellation.cancel() })
|
||||
}
|
||||
}
|
||||
|
||||
/// Admission control is read on workers; starting playback reduces future admissions.
|
||||
final class WaveformWorkload: @unchecked Sendable {
|
||||
static let shared = WaveformWorkload()
|
||||
@@ -172,9 +199,20 @@ extension WaveformBatch {
|
||||
let tracks = groups[next];next += 1;active += 1
|
||||
state.current = tracks.first?.title ?? "Preparing waveforms…"
|
||||
group.addTask(priority:.utility) {
|
||||
run(songs:tracks,locations:locations,cache:cache,force:force,cancelled:{Task.isCancelled})
|
||||
do {
|
||||
return try await WaveformWorker.run { cancelled in
|
||||
run(songs:tracks,locations:locations,cache:cache,force:force,cancelled:cancelled)
|
||||
}
|
||||
} catch {
|
||||
var result = WaveformJobProgress(total:tracks.count)
|
||||
result.cancelled = true;result.finished = true
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
// Publish admission before awaiting a decoder: otherwise a long first track
|
||||
// leaves the interface at “Preparing waveforms” with no visible activity.
|
||||
if active > 0 { progress(state) }
|
||||
guard active > 0,let result = await group.next() else { break }
|
||||
active -= 1
|
||||
state.processed += result.processed;state.generated += result.generated;state.cached += result.cached
|
||||
|
||||
Reference in New Issue
Block a user