File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Sources/ComposableArchitecturePattern Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // AsyncStreamable.swift
3+ // ComposableArchitecturePattern
4+ //
5+ // Created by Jonathan Holland on 10/5/25.
6+ //
7+
8+ /// A protocol for streaming a value.
9+ public protocol _AsyncStreamable {
10+ associatedtype Value : Sendable
11+ /// The underlying value to be streamed.
12+ var value : AsyncStreamPublisher < Value > { get }
13+ }
14+
15+ /// An actor to handle streaming for a value.
16+ public actor AsyncStreamable < T: Sendable > : _AsyncStreamable {
17+ nonisolated ( unsafe) public var value : AsyncStreamPublisher < T >
18+
19+ /// Create a new `AsyncStreamable` with the specified `AsyncStreamPublisher`.
20+ public init ( value: AsyncStreamPublisher < T > ) {
21+ self . value = value
22+ }
23+
24+ /// Create a new `AsyncStreamable` with the specified underlying value.
25+ public init ( value: T ) {
26+ self . value = AsyncStreamPublisher ( wrappedValue: value)
27+ }
28+
29+ /// Update the underlying value with the new value.
30+ public func update( to newValue: T ) {
31+ self . value. wrappedValue = newValue
32+ }
33+
34+ /// A new stream on the underlying value.
35+ public func stream( ) async -> AsyncStream < T > {
36+ self . value. newStream ( )
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments