Avatar
@matsuji @shimastripe AsyncStream を使った場合は next までの間に yield されても消失しないみたいですね。バッファに貯められてるっぽいです。 let values: AsyncStream<Int> = .init { continuation in Task { for i in 0 ..< 100 { try? await Task.sleep(nanoseconds: 100_000_000) continuation.yield(i) } continuation.finish() } } for await value in values { print(value) try await Task.sleep(nanoseconds: 1_000_000_000) }
3:18 PM
↓だと、さっき教えてもらった通り消失しました。 let subject: PassthroughSubject<Int, Never> = .init() let values = subject.values Task { for i in 0 ..< 100 { try? await Task.sleep(nanoseconds: 100_000_000) subject.send(i) } subject.send(completion: .finished) } for await value in values { print(value) try await Task.sleep(nanoseconds: 1_000_000_000) }
👀 1
3:20 PM
Publishervalues は危険そうですね・・・。