Sync to Async pipe?

I have a synchronous thread that Writes data, but the thread consuming it is async and thus needs an AsyncRead. I don't really know how to get started on accomplishing something like this, any suggestions?

You can use a duplex stream for this. The synchronous side will need to use block_on to actually perform the write — you can provide a wrapper that uses a Handle to do a blocking write to the duplex stream.

Consider if you are able to use an tokio::sync::mpsc instead of an Write, as it has native support for blocking sends. Also check out the chapter on bridging with sync code in the Tokio tutorial.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.