Improved the Capturing protocol in the Recording package target to capture interruptions and pause any active capture process.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user