Channels between threads and async tasks

Hey All,

I'm starting to wrap my head around communications between async tasks, but am not sure about communicating between external threads and tasks.

For example, I have a callback coming in from a C library (on a library thread) and I just want to take the data and queue it so that a receiver task can await it. Can I use a futures-based channel like futures::channel::mpsc? Or would it be better to implement a stream directly?

I also want to do this in my own Rust wrapper library without committing to an explicit runtime for an app that would be awaiting the data. If that makes sense.

Thanks

When using bounded channels, always use async-aware channels with a block_on in the synchronous side.

When using unbounded channels, use the one corresponding to the receiver. E.g. when sending to async, use async-aware channels, and when sending to sync use crossbeam or std channels.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.