Skip to content

[AsyncStreaming] Introduce a MultiProducerSingleConsumerChannel and a duplex - #425

Closed
FranzBusch wants to merge 2 commits into
apple:mainfrom
FranzBusch:fb-async-streaming-mpsc
Closed

[AsyncStreaming] Introduce a MultiProducerSingleConsumerChannel and a duplex#425
FranzBusch wants to merge 2 commits into
apple:mainfrom
FranzBusch:fb-async-streaming-mpsc

Conversation

@FranzBusch

Copy link
Copy Markdown
Member

Motivation

When working with async reader and writer one often needs "root" readers and writers. A multi producer single consumer channel can provide the foundation for such a reader and writer pair. Furthermore, developers often want a connected duplex pair of readers and writers for testing or in-memory purposes.

Modifications

This PR brings over the existing MultiProducerSingleConsumerAsyncChannel with adaptions to handle reader and writer like interfaces and leverage unstable types such as UniqueDeque. Furthermore, this PR also brings a DuplexStream that sets up two connected pairs of MPSC channels.

I intentionally copied and modified the MPSC implementation since I don't want to carry #if conditionals in an existing used implementation. Once we stabilize this module we can evaluate how to best proceed.

Result

Makes it easier for developers to work with readers and writers. In particular, makes testing a lot easier.

@FranzBusch
FranzBusch force-pushed the fb-async-streaming-mpsc branch 2 times, most recently from e02ca0f to b793e0e Compare May 27, 2026 14:29
@FranzBusch
FranzBusch marked this pull request as ready for review June 2, 2026 06:16
backpressureStrategy: BackpressureStrategy,
isolation: isolated (any Actor)? = #isolation,
body: (
consuming sending Writer,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 2 pairs? One pair is more commonly used and you can always build 2 from 1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MPSCChannel is a single pair the duplex is just two pairs connected bi-directionally. Both of them are important and yes one can be build using the other. In fact this PR does that. Having a connected duplex stream is very useful for many testing scenarios.

@guoye-zhang guoye-zhang changed the title [AsyncStremaing] Introduce a MultiProducerSingleConsumerChannel and a duplex [AsyncStreaming] Introduce a MultiProducerSingleConsumerChannel and a duplex Jun 4, 2026
@Catfish-Man

Copy link
Copy Markdown
Member

Sent you a patch on Slack to fix the tests building. With that I'm ok with landing this

@guoye-zhang

Copy link
Copy Markdown
Contributor

Merged in #428

@guoye-zhang guoye-zhang closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants