Improved the Capturing protocol in the Recording package target to capture interruptions and pause any active capture process.

This commit is contained in:
2026-07-04 15:19:26 +02:00
parent 6a0e7698a5
commit 1f1ac630f3
5 changed files with 211 additions and 17 deletions
@@ -6,6 +6,13 @@ import Foundation
/// state machine for example, with a real microphone backend in the app, or with a mock in unit tests.
public protocol Capturing: Sendable {
// MARK: Properties
/// The stream of events the service emits outside its method calls.
///
/// Defaults to an empty stream that finishes immediately, for services that emit no events.
var events: AsyncStream<CapturingEvent> { get }
// MARK: Methods
/// Starts a new audio recording from the microphone.
@@ -23,3 +30,24 @@ public protocol Capturing: Sendable {
func stop() async throws -> URL
}
// MARK: - Implementations
public extension Capturing {
/// The empty stream of events, which finishes immediately, for services that emit no events.
var events: AsyncStream<CapturingEvent> {
AsyncStream { continuation in
continuation.finish()
}
}
}
// MARK: - Events
/// An event emitted by a ``Capturing`` service outside its method calls.
public enum CapturingEvent: Sendable {
/// The system interrupted the ongoing capture, pausing it.
case interrupted
}