# 'Consuming an AsyncStream from multiple Tasks' Redux

**URL:** <https://forums.swift.org/t/consuming-an-asyncstream-from-multiple-tasks-redux/69818>\
**Category:** Using Swift\
**Tags:** concurrency\
**Created:** [February 3, 2024, 9:20pm UTC](https://forums.swift.org/t/consuming-an-asyncstream-from-multiple-tasks-redux/69818 "2024-02-03T21:20:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![FranzBusch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/franzbusch/32/19447_2.png) [@FranzBusch](https://forums.swift.org/u/FranzBusch)\
**Post date:** [February 5, 2024, 3:21pm UTC](https://forums.swift.org/t/consuming-an-asyncstream-from-multiple-tasks-redux/69818/2 "2024-02-05T15:21:35Z")

</div>

I have called out this behavioural difference in my backpressured async stream proposal [SE-0406](https://github.com/apple/swift-evolution/blob/main/proposals/0406-async-stream-backpressure.md). I agree that this is confusing and we should rectify the implementation; however, there are applications that depend on the current behaviour and enforcing the fatal error might break those.

It is my opinion, that `Async[Throwing]Stream` is a single consumer async sequence that should support only a single iterator to be created and that iterator doesn't allow concurrent consumption. In fact, the current implementation somewhat enforces this since a cancellation of a single call to `next()` will terminate the whole stream. I can recommend taking a look at [my PR](https://github.com/apple/swift-async-algorithms/pull/305) over in `swift-async-algorithms` where I am intending to land an externally backpressured single consumer async sequence.

Coming back to the root of your question. I agree that implementing a multi consumer async algorithm is important and I have a few approaches lying around. The main question when implementing such an algorithm is how the back pressured should be applied i.e. should the slowest consumer dictate the speed or should slow consumer buffer elements potentially ballooning the memory of a process.

---

_[View the full topic](https://forums.swift.org/t/consuming-an-asyncstream-from-multiple-tasks-redux/69818)._
