diff --git a/book/src/async.md b/book/src/async.md index b4c696a36..9482e92d9 100644 --- a/book/src/async.md +++ b/book/src/async.md @@ -84,3 +84,25 @@ void shim_doThing( }); } ``` + +### Streams + +The async example above can be extended to support streaming data as well using a channel such as [`futures::channel::mpsc::unbounded`] instead of oneshot and passing `DoThingContext` to the closure as a reference: + +[`futures::channel::mpsc::unbounded`]: https://docs.rs/futures/0.3.8/futures/channel/mpsc/fn.unbounded.html + +```cpp +// bridge_shim.cc + +#include "path/to/bridge.rs.h" +#include "rust/cxx.h" + +void shim_doThing( + Arg arg, + rust::Fn done, + rust::Box ctx) noexcept { + done(*ctx, std::move(res)); + done(*ctx, std::move(res)); + done(*ctx, std::move(res)); +} +```