Ah yea that might be an additional algorithm/interface that is needed.
We could streamline it with tricks via auto-closure:
public func deferred<Base: AsyncSequence>(_ base: @autoclosure () -> Base) -> AsyncDeferredSequence<Base>
That way we can reduce the call site to be a bit more succinct.
deferred(AsyncStream { continuation in
let monitor = QuakeMonitor()
monitor.quakeHandler = { quake in
continuation.yield(quake)
}
continuation.onTermination = { @Sendable _ in
monitor.stopMonitoring()
}
monitor.startMonitoring()
}).replay(history: 1)
And I think the replay behavior probably should be its own algorithm and not per-se wrapped up in broadcast itself. For that particular part of the family of multicast algorithms I do wonder if there is a utility of ever not having a deferred base? e.g. is the concept of replaying always based upon deferred access?