'Consuming an AsyncStream from multiple Tasks' Redux

I have called out this behavioural difference in my backpressured async stream proposal SE-0406. 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 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.

5 Likes