Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions book/src/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(const DoThingContext &ctx, Ret ret)> done,
rust::Box<DoThingContext> ctx) noexcept {
done(*ctx, std::move(res));
done(*ctx, std::move(res));
done(*ctx, std::move(res));
}
```