Skip to content

Commit 7178442

Browse files
authored
Merge pull request #26 from togglebyte/dev
updated async example
2 parents 7c2f931 + 0446f0b commit 7178442

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/recipes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Various recipes for solving certain common scenarios.
44

55
* [Routing views](./recipes/viewrouting.md)
66
* [Async](./recipes/async.md)
7-
* [Themes](./recipes/themes.md)
7+
* [Themes](./recipes/themes.md) (not done yet)

src/recipes/async.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ run the async code on a separate thread from the main thread.
99

1010
## Setting up for async
1111

12-
A function that starts an async runtime in a new thread.
12+
Create a function that starts an async runtime in a new thread.
1313

14-
By accepting a component id and an emitter it is possible to send messages into
14+
Using a component id and an emitter it is possible to send messages into
1515
the Anathema runtime.
1616

17+
In this example we assume there is a component that accepts a `usize` as its
18+
`Message` type.
19+
1720
```rust,ignore
18-
pub fn run_async(emitter: Emitter, component: ComponentId<MessageType>) {
21+
pub fn run_async(emitter: Emitter, component: ComponentId<usize>) {
1922
thread::spawn(move || {
2023
tokio::runtime::Builder::new_multi_thread()
2124
.enable_all()
2225
.build()
2326
.unwrap()
2427
.block_on(async move {
2528
// async code here
29+
emitter.emit_async(component, 123).await;
2630
});
2731
});
2832
}

0 commit comments

Comments
 (0)