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,9 @@ import Recording
@MainActor
final class CapturingMock: Capturing {
/// The stream of events the service emits outside its method calls.
let events: AsyncStream<CapturingEvent>
/// The duration every method takes before returning, simulating slow capture work.
var delay: Duration = .zero
@@ -15,6 +18,18 @@ final class CapturingMock: Capturing {
/// The names of the methods called on the service, in call order.
private(set) var calls: [String] = []
/// The continuation that feeds ``events``.
private let continuation: AsyncStream<CapturingEvent>.Continuation
init() {
(events, continuation) = AsyncStream.makeStream(of: CapturingEvent.self)
}
/// Emits an interruption of the ongoing capture through ``events``.
func interrupt() {
continuation.yield(.interrupted)
}
func start() async throws {
try await called("start")
}