mirror of
https://github.com/HaishinKit/HaishinKit.swift.git
synced 2026-05-07 20:12:28 +00:00
33 lines
924 B
Swift
33 lines
924 B
Swift
import Foundation
|
|
|
|
@propertyWrapper
|
|
package struct AsyncStreamed<T: Sendable & Equatable> {
|
|
package var wrappedValue: AsyncStream<T> {
|
|
get {
|
|
defer {
|
|
continuation.yield(value)
|
|
}
|
|
return stream
|
|
}
|
|
@available(*, unavailable)
|
|
set { _ = newValue }
|
|
}
|
|
package var value: T {
|
|
didSet {
|
|
guard value != oldValue else {
|
|
return
|
|
}
|
|
continuation.yield(value)
|
|
}
|
|
}
|
|
private let stream: AsyncStream<T>
|
|
private let continuation: AsyncStream<T>.Continuation
|
|
|
|
package init(_ value: T, bufferingPolicy limit: AsyncStream<T>.Continuation.BufferingPolicy = .unbounded) {
|
|
let (stream, continuation) = AsyncStream.makeStream(of: T.self, bufferingPolicy: limit)
|
|
self.value = value
|
|
self.stream = stream
|
|
self.continuation = continuation
|
|
}
|
|
}
|